简体   繁体   中英

panel linear model (using plm package) returns “model frame and formula mismatch in model.matrix()”

I'm trying to compute a linear model from panel data I have.

It looks something like this:

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")

The panel looks like this

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

Any idea why R keeps returning this?

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()

My guess is that you do not have enough data for lag(GDP, 5) and lag(Gini, 5) to be computed and thus, you get NA as returned values. It looks like you only have 3 years available but you request the 5th lag of those variables.

Try lag(data.01$GDP, 5) directly in the console and look at that output [if data.01 is a pdata.frame, if not, convert it to such].

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM