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

Marco
  • 2,368
  • 6
  • 22
  • 48
Dr. Yutam
  • 89
  • 1
  • 2
  • 5
    I do not believe that `stargazer` supports this kind of model. However, it is supported out-of-the-box by the [`modelsummary` package](https://vincentarelbundock.github.io/modelsummary/). 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) – Vincent Feb 20 '21 at 02:02
  • @Vincent This should be an answer – Jakob Nov 01 '21 at 13:48
  • 1
    @Jakob 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: https://vincentarelbundock.github.io/modelsummary/articles/modelsummary.html#fixest-fixed-effects-and-instrumental-variable-regression – Vincent Nov 01 '21 at 13:56
  • @Vincent 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. – Jakob Nov 02 '21 at 15:03
  • @Jakob Good point. I added an answer. – Vincent Nov 02 '21 at 15:32

3 Answers3

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

Vincent
  • 15,809
  • 7
  • 37
  • 39
3

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

rafa.pereira
  • 13,251
  • 6
  • 71
  • 109
0

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

Macaulay
  • 59
  • 1
  • 8