'Is there anyway to export feols model using stargazer in R?

I ran a bunch of model using feols model (fixest package), but I have trouble exporting my model into a table using stargazer. Any suggestions on how I can do that?

It does seem like I can use "etable" function, but I want to use stargazer because I want to add a couple lines of notes to my table and format the table the way I want it (e.g. using "table.layout" function in stargazer).



Solution 1:[1]

I do not believe that stargazer supports this kind of model. However, it is supported out-of-the-box by the modelsummary package. This package allows you to add notes, and the tables it produces are extremely customizable, because modelsummary supports several backend packages to create and customize tables: kableExtra, gt, flextable, huxtable. Tables can also be exported to many formats, including HTML, Markdown, LaTeX, JPG, data.frame, or PDF.

(Disclaimer: I am the author of modelsummary.)

Here is an example with a simple linear regression model:

library(fixest)
library(modelsummary)

# create a toy dataset
base <- iris
names(base) <- c("y", "x1", "x_endo_1", "x_inst_1", "fe")
base$x_inst_2 <- 0.2 * base$y + 0.2 * base$x_endo_1 + rnorm(150, sd = 0.5)
base$x_endo_2 <- 0.2 * base$y - 0.2 * base$x_inst_1 + rnorm(150, sd = 0.5)

# estimate
mod <- feols(y ~ sw(x1, x_endo_1, x_inst_1) | fe, data = base)

# table
modelsummary(mod)

enter image description here

You can use the various formula functions that fixest offers like step-wise inclusion of covariates:

mod <- feols(y ~ sw(x1, x_endo_1, x_inst_1) | fe, data = base)
modelsummary(mod)

enter image description here

And modelsummary also supports instrumental variable estimation. This will show both stages side-by-side:

mod <- feols(y ~ x1 | fe | x_endo_1 + x_endo_2 ~ x_inst_1 + x_inst_2, data = base)
modelsummary(summary(mod, stage = 1:2))

enter image description here

Solution 2:[2]

You may also use the etable function from fixest to export output tables:

library(fixest)
data("mtcars")

# models
model1 <- feols(mpg ~ cyl + disp, data=mtcars)
model2 <- feols(mpg ~ cyl +  hp, data=mtcars)

# data.frame output
df <- etable(list(model1, model2), tex=FALSE)

# Latex output
etable(list(model1, model2), tex=TRUE)

You can also save the output locally with the file parameter.

etable(list(model1, model2), tex=FALSE, file ='tt.txt')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vincent
Solution 2 rafa.pereira