4

I'd like to report the first and the second stage results from feols() IV regression using modelsummary(). I couldn't find a way (except running the first stage as a separate model).

I can display first and second stage results using etable() like this:

library(fixest)
library(tidyverse)
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 an instrumental variable model
mod <- feols(y ~ x1 | fe | x_endo_1 + x_endo_2 ~ x_inst_1 + x_inst_2, base)

# First and second stage results
etable(mod, stage = 1:2)

I'd appreciate any pointers.

Thanks, Umut

Umut
  • 87
  • 6
  • Not clear what you want to extract. the output from `etable` is a `data.frame` – akrun Oct 06 '21 at 18:12
  • I'd like to use`modelsummary::modelsummary()` . `modelsummary(mod)` only prints the second stage. Even though I can access to firststage with `mod$iv_firststage`, I couldn't manage to feed those results to `modelsummary()` – Umut Oct 06 '21 at 18:13
  • 1
    Does this give you what you want? `modelsummary::modelsummary(mod$iv_first_stage)`. I get what appears to be the first stage model summary. – xilliam Oct 06 '21 at 21:18
  • I think what doesn't work for me is to report first and second stage in the same table as in `modelsummary(mod, mod$iv_first_stage)`. It throws a "modelsummary could not extract goodness-of-fit statistics" error. – Umut Oct 06 '21 at 23:36

2 Answers2

5

From fixest documentation: enter image description here

To get both first and second stage, use summary with stage = 1:2. Then you can feed it to modelsummary:

modelsummary(summary(mod, stage = 1:2))

enter image description here

Laurent Bergé
  • 1,292
  • 6
  • 8
1

The first-stage IV regression model summary can be generated with:

modelsummary::modelsummary(mod$iv_first_stage)

modelsummary

xilliam
  • 2,074
  • 2
  • 15
  • 27