我能否使用lme4在面板数据上指定随机效应和固定效应模型?
我正在使用r重新执行Wooldridge(2013年,第494-5页)的示例14.4。感谢this site和this blog post,我已经成功在plm包中完成了它,但我想知道是否可以在lme4包中完成相同的操作?
第二步,我使用 plm 包估计了在例子14.4(Wooldridge 2013)中估计的三个模型。
我正在使用r重新执行Wooldridge(2013年,第494-5页)的示例14.4。感谢this site和this blog post,我已经成功在plm包中完成了它,但我想知道是否可以在lme4包中完成相同的操作?
这是我在plm包中完成的工作。非常感谢任何关于如何使用lme4完成相同工作的指导。首先,需要加载包和数据,
# install.packages(c("wooldridge", "plm", "stargazer"), dependencies = TRUE)
library(wooldridge)
data(wagepan)
第二步,我使用 plm 包估计了在例子14.4(Wooldridge 2013)中估计的三个模型。
library(plm)
Pooled.ols <- plm(lwage ~ educ + black + hisp + exper+I(exper^2)+ married + union +
factor(year), data = wagepan, index=c("nr","year") , model="pooling")
random.effects <- plm(lwage ~ educ + black + hisp + exper + I(exper^2) + married + union +
factor(year), data = wagepan, index = c("nr","year") , model = "random")
fixed.effects <- plm(lwage ~ I(exper^2) + married + union + factor(year),
data = wagepan, index = c("nr","year"), model="within")
第三步,我使用stargazer输出结果,以模拟Wooldridge(2013)中的表14.2。
stargazer::stargazer(Pooled.ols,random.effects,fixed.effects, type="text",
column.labels=c("OLS (pooled)","Random Effects","Fixed Effects"),
dep.var.labels = c("log(wage)"), keep.stat=c("n"),
keep=c("edu","bla","his","exp","marr","union"), align = TRUE, digits = 4)
#> ======================================================
#> Dependent variable:
#> -----------------------------------------
#> log(wage)
#> OLS (pooled) Random Effects Fixed Effects
#> (1) (2) (3)
#> ------------------------------------------------------
#> educ 0.0913*** 0.0919***
#> (0.0052) (0.0107)
#>
#> black -0.1392*** -0.1394***
#> (0.0236) (0.0477)
#>
#> hisp 0.0160 0.0217
#> (0.0208) (0.0426)
#>
#> exper 0.0672*** 0.1058***
#> (0.0137) (0.0154)
#>
#> I(exper2) -0.0024*** -0.0047*** -0.0052***
#> (0.0008) (0.0007) (0.0007)
#>
#> married 0.1083*** 0.0640*** 0.0467**
#> (0.0157) (0.0168) (0.0183)
#>
#> union 0.1825*** 0.1061*** 0.0800***
#> (0.0172) (0.0179) (0.0193)
#>
#> ------------------------------------------------------
#> Observations 4,360 4,360 4,360
#> ======================================================
#> Note: *p<0.1; **p<0.05; ***p<0.01
lme4
是最大似然框架,因此不会是“相同的”:plm 的vignette第7章与pkgnlme
进行了一些比较,这类似于lme4
,您应该能够从中获取信息。 - Helix123