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

3

7

I ran a bunch of models 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).

Russom answered 19/2, 2021 at 22:53 Comment(5)
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 tables are infinitely customizable. Of course, this is a different package, which is why I write this as a comment instead of an answer. (Disclaimer: I am the author)Mosstrooper
@Mosstrooper This should be an answerPerish
@Perish I wasn't sure because the author explicitly states that they want to use one specific argument of the stargazer package. FWIW, there's a fixest example on the website: vincentarelbundock.github.io/modelsummary/articles/…Mosstrooper
@Mosstrooper I get that but if you google how to make fixest latex tables, you arrive here. And if you're in a rush you won't look into the comments.Perish
@Perish Good point. I added an answer.Mosstrooper
M
9

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

Mosstrooper answered 2/11, 2021 at 15:31 Comment(0)
L
4

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')

Labonte answered 27/1, 2022 at 16:51 Comment(0)
R
0

As of fixest 0.10.2, table notes are now supported in etable.

Raddi answered 29/9, 2022 at 20:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.