我正在从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中报告的R平方(0.18062),至少在这种情况下,类似于Stata报道的R-sq Within(0.1799)。有没有什么方法可以获得R-sq在(0.1860)和Stata报告的总体(0.1830)之间?
答案 0 :(得分:0)
this website有完整的代码来重现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