I have data for three different years and are running a regression for each seperate year with lmList(). When I try to get the LaTex code with stargazer, I get an error saying it doesn't recognize the object type. When running stargazer for a normal linear regression, it works just fine, even though the class for the objects are the same.
This is my regression with lmList
fit <- lmList((lndeltaoms) ~ size + factor(gender)| year, data = tser)
stargazer(fit[["2008"]])
% Error: Unrecognized object type.
Compare this to a normal regression, where it works.
fit2 <- lm((lndeltaoms) ~ size + factor(gender), data=tser)
stargazer(fit2)
But when i compare the classes, they're the same.
class(fit[["2008"]])
[1] "lm"
class(fit2)
[1] "lm"
Since they're the same class, it feels stargazer should recognize both of them in the same way, but there seems to be some issue when extracting a model from the lmList.
Is there any way I can work around this?
It should work fine with lmList()
from the nlme
package (not the one from the lme4
). Try out:
fit1 <- nlme::lmList((lndeltaoms) ~ size + factor(gender)| year, data = tser)
stargazer(fit1[["2008"]]) # ok
fit2 <- lme4::lmList((lndeltaoms) ~ size + factor(gender)| year, data = tser)
stargazer(fit2[["2008"]]) # this does not work
It looks like stargazer()
works fine with objects of class lmList
but not with lmList4
object resulting from lme4::lmList()
.
Also, be careful while loading nlme
since its function lmList()
is masked from lme4::lmList()
.