R -plm - 内部误差和随机效应模型(汇集,之间和一阶差异工作)

R -plm - error within and random effects models (pooling, between & first differences work)

我对 Within 和随机效应方法有问题(它不起作用)。我对汇集、间差或一阶差分估计器没有问题 - >它有效。

我和R - Error in class(x) - plm - only within and random effects models有同样的问题。 这是我的数据 link:https://www.dropbox.com/s/8tgeyhxeb0wrdri/my_data.xlsx?raw=1(一些国家有一些金融措施和 GDP 增长)

我的代码:

proba<-read_excel("my_data.xlsx")
attach(proba)

Y<-cbind(GDP_growth)
X<-cbind(gfdddi01, gfdddi02, gfdddi04, gfdddi05)
pdata<-pdata.frame(proba,index=c("id","year"))
##POOLED OLS estimator
pooling<-plm(Y~X,data=pdata,model="pooling")
summary(pooling)

##BETWEEN ESTIMATOR
between<-plm(Y~X,data=pdata,model="between")
summary(between)

#FIRST DIFFERENCES ESTIMATOR
firstdiff<-plm(Y~X,data=pdata,model="fd")
summary(firstdiff)

#FIXED EFFECT OR WITHIN ESTIMATOR
fixed <-plm(Y~X,data=pdata,model="within")
summary(fixed)

#RANDOM EFFECTS ESTIMATOR
random<- plm(Y~X,data=pdata,model="random")
summary(random)

我收到的错误消息:

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)

有什么问题吗?

不要使用环境中的变量(就像您对 YX 所做的一样 - 无需创建它们)。相反,在 plmformula 参数中使用数据中出现的变量名称 pdata:

#FIXED EFFECT OR WITHIN ESTIMATOR
fixed <-plm(GDP_growth ~ gfdddi01 + gfdddi02 + gfdddi04 + gfdddi05, data = pdata, model ="within")
summary(fixed)

## Oneway (individual) effect Within Model
## 
## Call:
## plm(formula = GDP_growth ~ gfdddi01 + gfdddi02 + gfdddi04 + gfdddi05, 
##     data = pdata, model = "within")
## 
## Balanced Panel: n = 17, T = 41, N = 697
## 
## Residuals:
##      Min.   1st Qu.    Median   3rd Qu.      Max. 
## -18.89148  -1.17470   0.12701   1.48874  20.70109 
## 
## Coefficients:
##            Estimate Std. Error t-value Pr(>|t|)
## gfdddi01 -0.0066663  0.0153800 -0.4334   0.6648
## gfdddi02  0.0051626  0.0153343  0.3367   0.7365
## gfdddi04 -0.0245573  0.0150069 -1.6364   0.1022
## gfdddi05 -0.0049627  0.0073786 -0.6726   0.5014
## 
## Total Sum of Squares:    5421.5
## Residual Sum of Squares: 5366.8
## R-Squared:      0.010095
## Adj. R-Squared: -0.019192
## F-statistic: 1.72352 on 4 and 676 DF, p-value: 0.14296