2016-01-25 48 views
0

我試圖從面板數據中計算線性模型。面板線性模型(使用plm包)返回「model.matrix()中的模型框架和公式不匹配」​​

它看起來是這樣的:

model <- plm((log(GDP)-log(lag(GDP,5))) ~ log(lag(GDP,5)) + (lag(Gini,5)) 
+ GFCF + Schooling, data=data.01, index=c("Country", "Year"), model="within") 

面板看起來像這樣

Country Year GDP  Gini GFCF Schooling 
A  1970 21400 0.33 0.22 10.11 
A  1971 21350 0.34 0.23 10.70 
A  1972 21600 0.33 0.23 10.90 
B  1970 18500 0.29 0.17 9.80 
B  1971 19000 0.28 0.17 9.90 
B  1972 20800 0.28 0.15 10.50 

任何想法,爲什麼者繼續回來呢?

series Gini, X are NA and have been removed 
Error in model.matrix.default(mt, data = data, ...) : 
    model frame and formula mismatch in model.matrix() 

回答

0

我的猜測是,你沒有足夠的數據lag(GDP, 5)lag(Gini, 5)來計算,因此,你會得到NA返回的值。看起來你只有3年可用,但你要求這些變量的第5次滯後。

嘗試lag(data.01$GDP, 5)直接在控制檯中查看該輸出[如果data.01是pdata.frame,如果不是,則將其轉換爲此類]。