我希望在面板数据中运行回归。我的索引中有NA(ID,时间)。我不想删除索引中的NA。
Result<-plm(TBL~Tang+Prof+LnSALES+MB,data=Panel,model="within",index=c("Firms","Time"))
当我上面的代码时,它返回:
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
如果没有删除NA,如何在索引中使用NA运行面板回归? 感谢
答案 0 :(得分:2)
由于您只是想省略索引为NA
的观察,您可以这样做:
Result <- plm(TBL ~ Tang + Prof + LnSALES + MB,
data=Panel[which(!is.na(Panel$Firms)), ],
model="within", index=c("Firms", "Time"))
data=Panel[which(!is.na(Panel$Firms)), ]
告诉plm()
将Panel
的{{1}}的子集用作Panel$Firms
不是NA
的数据。那你就不能解决问题了
at least one couple (id-time) has NA in at least one index dimension in
resulting pdata.frame