5

我正在从 Stata 迁移到 R ( plm package) 以进行面板模型计量经济学。在 Stata 中,随机效应等面板模型通常报告内部、中间和整体 R 平方。

我发现随机效应模型中报告的 R 平方plm对应于 R 平方内。那么,有没有办法使用plm packagein R 来获得整体和 R 平方之间的关系?

请参阅与 R 和 Stata 相同的示例:

library(plm)
library(foreign) # read Stata files
download.file('http://fmwww.bc.edu/ec-p/data/wooldridge/wagepan.dta','wagepan.dta',mode="wb")
wagepan <- read.dta('wagepan.dta')

# Random effects
plm.re <- plm(lwage ~ educ + black + hisp + exper + expersq + married + union + d81 + d82 + d83 + d84 + d85 + d86 + d87,
              data=wagepan,
              model='random',
              index=c('nr','year'))
summary(plm.re)

在Stata中:

use http://fmwww.bc.edu/ec-p/data/wooldridge/wagepan.dta
xtset nr year
xtreg lwage educ  black  hisp  exper  expersq  married  union  d81  d82  d83  d84  d85  d86  d87, re

至少在这种情况下,R (0.18062) 中报告的 R 平方与 Stata (0.1799) 中报告的 R-sq Within 相似。有什么方法可以在 R 中获得 Stata 报告的(0.1860)和总体(0.1830)之间的 R-sq?

4

1 回答 1

0

这个网站有完整的代码来重现 Wooldridge 2013 p 中的示例 14.4。494-5 带 R 平方。报告所有型号,

# install.packages(c("wooldridge"), dependencies = TRUE) 
# devtools::install_github("JustinMShea/wooldridge")
library(wooldridge) 
data(wagepan)

# install.packages(c("plm", "stargazer","lmtest"), dependencies = TRUE)
library(plm); library(lmtest); library(stargazer)

model <- as.formula("lwage ~ educ + black + hisp + exper+I(exper^2)+married + union+yr")
reg.ols <- plm(model, data = wagepan.p, model="pooling")

reg.re <- plm(lwage ~ educ + black + hisp + exper +
              I(exper^2) + married + union + yr, data = wagepan.p, model="random") 

reg.fe <- plm(lwage ~ I(exper^2) + married+union+yr, data=wagepan.p, model="within")

# Pretty table of selected results (not reporting year dummies)
stargazer(reg.ols,reg.re,reg.fe, type="text",
     column.labels=c("OLS","RE","FE"),
     keep.stat=c("n","rsq"),
     keep=c("ed","bl","hi","exp","mar","un"))

哪个输出,

#> ==========================================
#>                   Dependent variable:     
#>              -----------------------------
#>                          lwage            
#>                 OLS       RE        FE    
#>                 (1)       (2)       (3)   
#> ------------------------------------------
#> educ         0.091***  0.092***           
#>               (0.005)   (0.011)           
#>                                           
#> black        -0.139*** -0.139***          
#>               (0.024)   (0.048)           
#>                                           
#> hisp           0.016     0.022            
#>               (0.021)   (0.043)           
#>                                           
#> exper        0.067***  0.106***           
#>               (0.014)   (0.015)           
#>                                           
#> I(exper2)    -0.002*** -0.005*** -0.005***
#>               (0.001)   (0.001)   (0.001) 
#>                                           
#> married      0.108***  0.064***   0.047** 
#>               (0.016)   (0.017)   (0.018) 
#>                                           
#> union        0.182***  0.106***  0.080*** 
#>               (0.017)   (0.018)   (0.019) 
#>                                           
#> ------------------------------------------
#> Observations   4,360     4,360     4,360  
#> R2             0.189     0.181     0.181  
#> ==========================================
#> Note:          *p<0.1; **p<0.05; ***p<0.01
于 2018-01-30T21:40:40.910 回答