面板数据回归

Reads: 2328 Edit

1 数据

R可以方便的对面板数据进行分析。我们以EconomicData.sav的数据为例进行演示,基于中国30个省市2011年至2018年的面板数据估计外商直接投资(pfdi)、对外贸易(open)、劳动人口受教育年限(eduyear)对人均GDP的影响。

2 安装面板数据模型plm包

> install.packages("plm")
> library(plm)

3 导入数据

> library(haven)
> panelData=read_dta("D:/Desktop/EconomicData.dta")
> View(panelData)

r-72

4 设置面板数据格式

> PData = pdata.frame(panelData,index = c("prov","year"))

5 混合面板估计

> pooling = plm(pgdp ~ eduyear+pfdi+open, data = PData,model = "pooling") 
> summary(pooling)
Pooling Model

Call:
plm(formula = pgdp ~ eduyear + pfdi + open, data = PData, model = "pooling")

Balanced Panel: n = 30, T = 8, N = 240

Residuals:
    Min.  1st Qu.   Median  3rd Qu.     Max. 
-2.99231 -0.77270 -0.27814  0.58971  4.53531 

Coefficients:
             Estimate Std. Error t-value  Pr(>|t|)    
(Intercept) -6.122498   1.126160 -5.4366 1.353e-07 ***
eduyear      1.114948   0.129990  8.5772 1.305e-15 ***
pfdi         4.131178   0.863377  4.7849 3.017e-06 ***
open         0.350009   0.042756  8.1861 1.689e-14 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Total Sum of Squares:    1482
Residual Sum of Squares: 340.19
R-Squared:      0.77045
Adj. R-Squared: 0.76754
F-statistic: 264.038 on 3 and 236 DF, p-value: < 2.22e-16

6 固定效应估计

> fixed = plm(pgdp ~ eduyear+pfdi+open, data = PData,model = "within") 
> summary(fixed)
Oneway (individual) effect Within Model

Call:
plm(formula = pgdp ~ eduyear + pfdi + open, data = PData, model = "within")

Balanced Panel: n = 30, T = 8, N = 240

Residuals:
    Min.  1st Qu.   Median  3rd Qu.     Max. 
-1.80547 -0.41447 -0.01872  0.34209  2.87503 

Coefficients:
        Estimate Std. Error t-value  Pr(>|t|)    
eduyear  2.73086    0.22207 12.2974 < 2.2e-16 ***
pfdi     4.57606    0.78647  5.8185 2.233e-08 ***
open     1.17815    0.20618  5.7143 3.802e-08 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Total Sum of Squares:    250.78
Residual Sum of Squares: 107.76
R-Squared:      0.57032
Adj. R-Squared: 0.50389
F-statistic: 91.5838 on 3 and 207 DF, p-value: < 2.22e-16  

7 估计随机效应

> random = plm(pgdp ~ eduyear+pfdi+open, data = PData,model = "random") 
> summary(random)
Oneway (individual) effect Random Effect Model 
   (Swamy-Arora's transformation)

Call:
plm(formula = pgdp ~ eduyear + pfdi + open, data = PData, model = "random")

Balanced Panel: n = 30, T = 8, N = 240

Effects:
                 var std.dev share
idiosyncratic 0.5206  0.7215 0.392
individual    0.8059  0.8977 0.608
theta: 0.7267

Residuals:
     Min.   1st Qu.    Median   3rd Qu.      Max. 
-2.014388 -0.461005 -0.097459  0.337473  3.199938 

Coefficients:
              Estimate Std. Error z-value  Pr(>|z|)    
(Intercept) -14.253480   1.684719 -8.4605 < 2.2e-16 ***
eduyear       2.020214   0.190513 10.6041 < 2.2e-16 ***
pfdi          3.424914   0.817656  4.1887 2.806e-05 ***
open          0.295670   0.082685  3.5759 0.0003491 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Total Sum of Squares:    342.76
Residual Sum of Squares: 151.91
R-Squared:      0.5568
Adj. R-Squared: 0.55116
Chisq: 296.487 on 3 DF, p-value: < 2.22e-16

8 豪斯曼检验

> phtest(random, fixed)

    Hausman Test

data:  pgdp ~ eduyear + pfdi + open
chisq = 69.079, df = 3, p-value = 6.722e-15
alternative hypothesis: one model is inconsistent

说明:p-value = 6.722e-15 < 0.05,因而拒绝原假设(随机效应),选择固定效应模型!



获取案例数据,请关注微信公众号并回复:R_dt3


Comments

Make a comment