ycroissant / plm

Panel Data Econometrics with R
GNU General Public License v2.0
49 stars 13 forks source link

Estimating a Two-way Random Effect Model Using lmer and plm #9

Closed ahnm2002 closed 3 years ago

ahnm2002 commented 3 years ago

I am using lmer to estimate a two-way random effect model like this y ~ x1 + x2 + (1|country) + (1|year).

When I use plm(y ~ x1 + x2, index = c("country", "year"), model = "random", effect = "twoways") I get totally different estimates. Here is a reproducible example:

if (!require("pacman")) install.packages("pacman")

pacman::p_load(stargazer, lme4,  plm)

library(gapminder)

fit.lmm <- lmer( log(lifeExp) ~ log(pop) + log(gdpPercap) + 
(1|year) + (1|country), data = gapminder)

fit.plm <- plm( log(lifeExp) ~ log(pop) + log(gdpPercap), data = 
gapminder, index = c("country","year"), model="random", effect = 
"twoways")

stargazer(fit.lmm, fit.plm, type="text")
tappek commented 3 years ago

No issue here. plm and lmer use different estimation techniques so one cannot expect identical results. You may read up on the methods used, e.g., in plm's Vignette as a starter https://cran.r-project.org/web/packages/plm/vignettes/A_plmPackage.html , section "plm versus nlme and lme4".

This has been asked before on SO (https://stackoverflow.com/questions/68801350/estimating-a-two-way-random-effect-model-in-r-using-lmer-and-plm), likely by the same poster; a comment there under the post already gave a similar response.