1

Using stargazer, is it possible to report several regression models stacked in rows underneath each other, rather than in separate columns next to each other? So that for each model there would be one row for the model name, and then one row for each of the model's coefficients?

For example, this is the standard output for multiple models in stargazer:

Term   Model1    Model2
Coef1  3.5       2.6
Coef2  2.1       3.1
Coef3            2.2

The long format output (i.e., the desired result) would look like this:

        Estimate
Model1  
Coef1    3.5
Coef2    2.1

Model2  
Coef1    2.6
Coef2    3.1
Coef3    2.2

Is there an easy way to get an output like this in stargazer?

Adam B.
  • 788
  • 5
  • 14

1 Answers1

2

sorry, I am not very familiar with stargazer (or its options). However, from my understanding, your task that would not be too bad using knitr::kable and the broom package. Below is a basic example, but you can do a lot more with it (there are great vignettes for using kableExtra).

library(knitr)
library(kableExtra)
library(dplyr)
library(broom)

mtcars <- mtcars

model1 <- lm(mpg ~ cyl + wt, data = mtcars)
model2 <- lm(mpg ~ cyl + wt + disp, data = mtcars)

coefs <- bind_rows(tidy(model1), tidy(model2))

coefs %>%
  kable(digits = 3) %>%
  kable_styling(full_width = FALSE) %>%
  group_rows("Model 1", 1, 3) %>%
  group_rows("Model 2", 4, 7)
Andrew
  • 5,028
  • 2
  • 11
  • 21
  • how do you add only the first right-hand variable in the table but not let's say the variables you factorized? – Oscar Thees Apr 09 '20 at 08:20
  • @OscarThees, does it need to automatically select non-factor variables, also, will the position always be the first IV? So, in the above example, will it always be the variable in the `cyl` spot? – Andrew Apr 09 '20 at 17:08