I am running a regression in R with a lot of time and location fixed effects. I try to output a nice summary table into Latex. I switched from stargazer
package to huxtable
because stargazer
does not behave consistently when omitting fixed effects (see this question).
Here is a simple example:
library(huxtable)
reg1 <- lm(mpg ~ disp, data = mtcars)
reg2 <- lm(mpg ~ disp + factor(gear) + factor(carb), data = mtcars)
huxreg(reg1, reg2)
The output of huxreg
is:
> huxreg(reg1, reg2)
────────────────────────────────────────────────────
(1) (2)
───────────────────────────────────
(Intercept) 29.600 *** 25.533 ***
(1.230) (2.996)
disp -0.041 *** -0.018
(0.005) (0.011)
factor(gear)4 3.988
(2.495)
factor(gear)5 5.391 *
(2.591)
factor(carb)2 -1.979
(1.667)
factor(carb)3 -4.161
(2.131)
factor(carb)4 -6.199 *
(2.221)
factor(carb)6 -8.557 *
(3.653)
factor(carb)8 -10.389 *
(4.268)
───────────────────────────────────
N 32 32
R2 0.718 0.828
logLik -82.105 -74.186
AIC 170.209 168.372
────────────────────────────────────────────────────
*** p < 0.001; ** p < 0.01; * p < 0.05.
Column names: names, model1, model2
Here is the desired output:
────────────────────────────────────────────────────
(1) (2)
───────────────────────────────────
(Intercept) 29.600 *** 25.533 ***
(1.230) (2.996)
disp -0.041 *** -0.018
(0.005) (0.011)
───────────────────────────────────
Gear FE No Yes
Carb FE No Yes
───────────────────────────────────
N 32 32
R2 0.718 0.828
logLik -82.105 -74.186
AIC 170.209 168.372
────────────────────────────────────────────────────
*** p < 0.001; ** p < 0.01; * p < 0.05.
Column names: names, model1, model2
I know I could simply edit the huxtable using add_rows()
, but I am looking for a more robust solution that would allow to find rownames using regular expressions (like stargazer's omit.labels
option).