I am using the following code to create a latex table using modelsummary
and kableExtra
. The code used to work but it seems that either modelsummary
or kableExtra
made some changes that made it harder to use both. Is there a way that editing the following table would result in a latex table being saved? I already tried change output = "kableExtra"
and the latex table was empty.
Here is the code I am using
mod_es = list(
"Poor Health" = emfx(models$`Poor Health`, type = "event", collapse = FALSE),
"School Lunch" = emfx(models$`School Lunch`, type = "event", collapse = FALSE),
"Log School Lunch" = emfx(models$`Log School Lunch`, type = "event", collapse = FALSE),
"SNAP" = emfx(models$`SNAP`, type = "event", collapse = FALSE),
"Log SNAP" = emfx(models$`Log SNAP`, type = "event", collapse = FALSE)
)
# Quick renaming function to replace ".Dtreat" with something more meaningful
rename_fn = function(old_names) {
new_names = gsub(".Dtreat", "Years post treatment =", old_names)
setNames(new_names, old_names)
}
f1 <- function(x) format(round(x, 3), big.mark=".")
f2 <- function(x) format(round(x, 0), big.mark=",")
gm <- list(
list(raw = "nobs", clean = "Observations", fmt = f2),
list(raw = "FE..first_treat", clean = "Cohort FE", fmt = 0),
list(raw = "FE..year", clean = "Year FE", fmt = 0),
list(raw = "std.error.type", clean = "Standard Errors", fmt = 0)
)
options("modelsummary_format_numeric_latex" = "plain")
regression_tab <- modelsummary(
mod_es,
fmt = f1,
shape = term:event:statistic ~ model,
coef_rename = rename_fn,
stars = c('***' = 0.01, '**' = 0.05, '*' = 0.1),
gof_map = gm,
escape = F,
output = "latex",
title = "Extended Two Way Fixed Effects \label{tab:etwfe}") |>
kable_styling(latex_options = c("scale_down", "HOLD_position")) |>
footnote(number = c("\\footnotesize{Each column is the results of the extended two-way fixed effects estimation.
Standard errors are clustered on the county level.}",
"\\footnotesize{Data source is the 1994-2019 Current Population Survey.}"),
footnote_as_chunk = F, title_format = c("italic"),
escape = F, threeparttable = T, fixed_small_size = T)
regression_tab %>%
save_kable(file.path(tables_wd,"tab01-etwfe.tex"))
I tried the code above that I ran many times before and was expecting the table to be saved in a script called tab01-etwfe.tex
.