2013-09-26 136 views
9

我希望同事能夠複製我用Stata和R(或其他軟件包)中的plm包進行估算的第一差分線性面板數據模型。R和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文檔,但我一定錯過了一些東西。

回答

10

由於在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 

塔塔

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 

塔塔:

. 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

+0

謝謝。我應該已經意識到,plm只是對差異數據運行OLS而不調整面板結構。有沒有辦法讓它聚集在ID(或更合適的東西)? –

+0

我已經更新了答案。但是,有一點差異。你可以檢查參考。 – Metrics

+0

它是否仍在「plm手冊」第39頁?或者它是關於'vcovHC魯棒協方差矩陣估計器'的一節,在第65頁(版本1.4-0)?謝謝 – pidosaurus