固定效应plm错误:lm中的错误。拟合(x,y,偏移=偏移,singular.ok=singular.ok,…):0(非NA)情况

固定效应plm错误:lm中的错误。拟合(x,y,偏移=偏移,singular.ok=singular.ok,…):0(非NA)情况,r,panel-data,plm,R,Panel Data,Plm,我正在尝试对我的数据运行固定效应估计器,即使池、中间和第一个差异估计器都有效,但在尝试固定效应估计器时,我始终会遇到以下错误: Error in class(x) <- setdiff(class(x), "pseries") : invalid to set the class to matrix unless the dimension attribute is of length 2 (was 0) 我在这里的其他帖子中也看到过这个错误,因此我尝试了所有建议的解决方案,但都没

我正在尝试对我的数据运行固定效应估计器,即使池、中间和第一个差异估计器都有效,但在尝试固定效应估计器时,我始终会遇到以下错误:

Error in class(x) <- setdiff(class(x), "pseries") : 
  invalid to set the class to matrix unless the dimension attribute is of length 2 (was 0)
我在这里的其他帖子中也看到过这个错误,因此我尝试了所有建议的解决方案,但都没有成功(写出所有变量,而不是使用环境中创建的“x”和“y”,使用all(is.na(x))进行测试), all(is.na(y))导致FALSE,表明这不是问题所在,包括na.action=na.exclude以删除na值…)没有任何效果,并且不断出现相同的错误。 这是我的密码:

mydata<- read.csv("/Users/hannahsalamon/Desktop/data.csv")
attach(mydata)
y<-cbind(RenEnCon)
x<-cbind(WomenParl, GDPpercap, Pop, UrbanPop, FreedomHouse, RegimeType, HDI, WomenPolEmpowerIndex)
pdata<-pdata.frame(mydata, index=c("Country", "Year"))
summary(y)
summary(x)
pooling<-plm(y~x, data = pdata, model = "pooling")
summary(pooling)
between<-plm(y~x, data = pdata, model = "between")
summary(between)
firstdiff<-plm(y~x, data = pdata, model = "fd")
summary(firstdiff)
fixed<-plm(y~x, data = pdata, model = "within")
fixed <- plm(RenEnCon ~ WomenParl+GDPpercap+UrbanPop+Pop+FreedomHouse+RegimeType+HDI+WomenPolEmpowerIndex, data=pdata, model= "within")

当然,就在发布这篇文章之后,
mydata找到了答案。对于其他人来说,如果这可能有帮助的话,我解决问题的方法是确保所有缺失的值都编码为NA。我有一些值被编码为NA,而其他值则用“.”填充。当我移除这些并将它们替换为NA值时,固定效果模型就开始工作了。我不知道为什么这对其他任何估计员来说都不是问题

这应该解决您的问题:
mydata<- read.csv("/Users/hannahsalamon/Desktop/data.csv")
attach(mydata)
y<-cbind(RenEnCon)
x<-cbind(WomenParl, GDPpercap, Pop, UrbanPop, FreedomHouse, RegimeType, HDI, WomenPolEmpowerIndex)
pdata<-pdata.frame(mydata, index=c("Country", "Year"))
summary(y)
summary(x)
pooling<-plm(y~x, data = pdata, model = "pooling")
summary(pooling)
between<-plm(y~x, data = pdata, model = "between")
summary(between)
firstdiff<-plm(y~x, data = pdata, model = "fd")
summary(firstdiff)
fixed<-plm(y~x, data = pdata, model = "within")
fixed <- plm(RenEnCon ~ WomenParl+GDPpercap+UrbanPop+Pop+FreedomHouse+RegimeType+HDI+WomenPolEmpowerIndex, data=pdata, model= "within")