R和Stata中的第一差分线性面板模型方差

时间:2013-09-26 01:25:35

标签: r stata standard-error plm

我希望一位同事复制一个第一差异线性面板数据模型,我正在使用R(或其他一些软件包)中的plm软件包与Stata进行估算。

在Stata中,xtreg没有第一个差异选项,因此我运行:

reg D.(y x), nocons cluster(ID)

在R中,我正在做:

plm(formula = y ~ -1 + x, data = data, model = "fd", index = c("ID","Period"))

系数匹配,但R中的标准误差大于Stata中的标准误差。我查看了plm帮助和pdf文档,但我必须遗漏一些东西。

1 个答案:

答案 0 :(得分:11)

标准错误不同,因为您在Stata中使用cluster选项。

<强> R:

data(Grunfeld)
library(plm)
grun.re <- plm(inv~-1+value+capital,data=Grunfeld,model="fd")
> summary(grun.re)
Oneway (individual) effect First-Difference Model

Call:
plm(formula = inv ~ -1 + value + capital, data = Grunfeld, model = "fd")

Balanced Panel: n=10, T=20, N=200

Residuals :
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
-202.00  -15.20   -1.76   -1.39    7.95  199.00 

Coefficients :
         Estimate Std. Error t-value  Pr(>|t|)    
value   0.0890628  0.0082341  10.816 < 2.2e-16 ***
capital 0.2786940  0.0471564   5.910  1.58e-08 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

<强>的Stata

 reg D.(inv value capital), nocons

      Source |       SS       df       MS              Number of obs =     190
-------------+------------------------------           F(  2,   188) =   70.58
       Model |   259740.92     2   129870.46           Prob > F      =  0.0000
    Residual |  345936.615   188  1840.08838           R-squared     =  0.4288
-------------+------------------------------           Adj R-squared =  0.4228
       Total |  605677.536   190   3187.7765           Root MSE      =  42.896

------------------------------------------------------------------------------
       D.inv |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       value |
         D1. |   .0890628   .0082341    10.82   0.000     .0728197    .1053059
             |
     capital |
         D1. |    .278694   .0471564     5.91   0.000     .1856703    .3717177

如果您想按组进行集群,这是解决方案:

<强> R:

library(lmtest) # for coeftest function
coeftest(grun.re,vcov=vcovHC(grun.re,type="HC0",cluster="group"))

t test of coefficients:

        Estimate Std. Error t value  Pr(>|t|)    
value   0.089063   0.013728  6.4878 7.512e-10 ***
capital 0.278694   0.130954  2.1282   0.03462 *  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

<强>的Stata:

. reg D.(inv value capital), nocons cluster(firm)

Linear regression                                      Number of obs =     190
                                                       F(  2,     9) =   47.80
                                                       Prob > F      =  0.0000
                                                       R-squared     =  0.4288
                                                       Root MSE      =  42.896

                                  (Std. Err. adjusted for 10 clusters in firm)
------------------------------------------------------------------------------
             |               Robust
       D.inv |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       value |
         D1. |   .0890628   .0145088     6.14   0.000     .0562416    .1218841
             |
     capital |
         D1. |    .278694    .138404     2.01   0.075    -.0343976    .5917857
------------------------------------------------------------------------------

你可以看到存在细微差别。有关R的详细信息,请参阅plm manual第39页以及herehere