Reputation: 1180
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?
Upvotes: 1
Views: 1162
Reputation: 5138
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)
Upvotes: 2