2

I want run regression in panel data. There is NA in my index (ID,time). I do not want to delete NA in index.

Result<-plm(TBL~Tang+Prof+LnSALES+MB,data=Panel,model="within",index=c("Firms","Time"))

When I the above code, it returns:

at least one couple (id-time) has NA in at least one index dimension in 
resulting pdata.frame 
to find out which, use e.g. table(index(your_pdataframe), useNA = "ifany")
Error in model.matrix.pFormula(formula, data, rhs = 1, model = model,  : 
NA in the individual index variable

Without delete NA, how can I run panel regression with NA in index? Thanks

  • 1
    Just think through the issue a little... If there's an `NA` in your index column, you have an observation of your variables that you don't know who it belongs to. How then is `plm` supposed to sort out the fixed effects for your `within` model? – duckmayr Nov 11 '17 at 22:34
  • 1
    Hi thanks, i mean just omit NA in index when regressing, not delete them from the data –  Nov 11 '17 at 22:47
  • 1
    How does `Result <- plm(TBL ~ Tang + Prof + LnSALES + MB, data=Panel[which(!is.na(Panel$Firms)), ], model="within", index=c("Firms", "Time"))` work? – duckmayr Nov 11 '17 at 23:08
  • Thanks a lot, it works –  Nov 12 '17 at 11:30
  • @duckmayr do you want to turn your comment into an answer? – Helix123 Nov 18 '17 at 12:23
  • @Helix123 yes, thanks for reminding me. I used the comment format first since I couldn't be sure it was a working answer without 1412MM's data, but hadn't gotten around to adding an answer after their feedback. – duckmayr Nov 18 '17 at 12:26

1 Answers1

2

Since you are just looking to omit observations where your index is NA, you can do this:

Result <- plm(TBL ~ Tang + Prof + LnSALES + MB,
              data=Panel[which(!is.na(Panel$Firms)), ],
              model="within", index=c("Firms", "Time"))

Explanation

data=Panel[which(!is.na(Panel$Firms)), ] tells plm() to use as data a subset of Panel where Panel$Firms is not NA. Then you cannot have the issue where

at least one couple (id-time) has NA in at least one index dimension in 
resulting pdata.frame
duckmayr
  • 16,303
  • 3
  • 35
  • 53