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

浪子不回头ぞ 提交于 2020-04-18 12:35:28

问题


I have problem with Within and random effect method (it doesn't work). And I have no problem with pooling, between or first diffeences estimator -> it works.

I have the same problem like R - Error in class(x) - plm - only within and random effects models. Here is the link to my data: https://www.dropbox.com/s/8tgeyhxeb0wrdri/my_data.xlsx?raw=1 (there are some financial measures and GDP growth for some countries)

My code:

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)

The error message I get:

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)

What can be wrong?


回答1:


Do not use variables from the environment (like you have done with Y and X - no need to create those). Rather, use in the formula argument of plm the variable names as they occur in your data 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


来源:https://stackoverflow.com/questions/60804415/r-plm-error-within-and-random-effects-models-pooling-between-first-differ

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!