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

I have found,即在plm随机效应模型中报告的R平方对应于R平方内。那么,有什么方法可以使用R中的plm package获得总体和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内部相似。有什么方法可以使Stata中报告的R-sq在(0.1860)和总体(0.1830)之间?

最佳答案

this website具有完整的代码,可以在Wooldridge 2013 p中重现示例14.4。带有R-sq的494-5。报告所有型号,

# 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

关于r - 计算R中的R平方,在R平方之间或在R平方中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34706378/

10-12 16:37