I am trying to create a regression table that has two panels with overlapping but not identical dependent variables. For each panel, I want a title indicating the name of each panel as well as the dependent variables for each regression.
# rm(list = ls())
data("mtcars")
# Regressions for panel 1
reg1 <- lm(mpg ~ cyl + disp, data = mtcars)
reg2 <- lm(cyl ~ cyl + disp, data = mtcars)
# Regressions for panel 2
reg3 <- lm(mpg ~ hp + drat, data = mtcars)
reg4 <- lm(cyl ~ hp + drat, data = mtcars)
reg5 <- lm(disp ~ hp + qsec, data = mtcars)
# Panel 1 output
panel1 <- stargazer::stargazer(
reg1, reg2,
float = TRUE,
header = FALSE,
model.numbers = FALSE,
omit.table.layout = "n",
multicolumn = FALSE,
dep.var.caption = "",
type = "latex",
align = TRUE,
digits = 2,
df = FALSE,
digits.extra = 2,
nobs = TRUE,
omit.stat = c("rsq", "adj.rsq", "ser")
)
# Panel 2 output
panel2 <-
stargazer::stargazer(
reg3, reg4, reg5,
float = TRUE,
header = FALSE,
model.numbers = FALSE,
omit.table.layout = "n",
multicolumn = FALSE,
dep.var.caption = "",
type = "latex",
align = TRUE,
digits = 2,
df = FALSE,
digits.extra = 2,
nobs = TRUE,
omit.stat = c("rsq", "adj.rsq", "ser")
)
# Plot panels together
table <-
starpolishr::star_panel(
panel1,
panel2,
panel.names = c(
"Panel 1",
"Panel 2"
),
same.summary.stats = FALSE,
same.lhs.vars = FALSE )
# Save as a .tex file
starpolishr::star_tex_write(
starlist = table,
file = paste0(here::here(), "/panel_mwes.tex"),
headers = FALSE
)
This code produces the following output:
What I need to change is 1) Move "Panel A: Panel 1" above the dependent variable names; and 2) add dependent variable names below "Panel B: Panel 2". Is there any good way of implementing this (in stargazer/starpolishr or otherwise) without being super hacky?