Suppose I have a table summarizing regressions using the modelsummary
package such as the following:
library(fixest)
library(modelsummary)
reg1 <- feols(hp ~ vs + am + qsec | carb, data = mtcars)
reg2 <- feols(wt ~ vs + am + qsec | carb, data = mtcars)
reg3 <- feols(gear ~ vs + am + qsec | carb, data = mtcars)
I plot the summary of the two regressions in a table such as the following:
tab <- modelsummary(list("HP" = reg1, "WT" = reg2, "GEAR" = reg3),stars = TRUE, statistic = c("s.e. = {std.error}"), estimate = "estimate", fmt = fmt_statistic(p.value = fmt_sprintf("%.2e")))
I now will add a column of values to the table using the argument add_columns(data.frame(c("x","","x","","","")))
This works, however it will give me an arbitrary column name. How can I rename this added column within the modelsummary
if I rename the vector/dataframe outside the modelsummary
this would not be ideal as I need to add multiple columns with shared names but different values.
Also, how can one add multiple columns in a different order within the add_columns
argument? For example, if I wanted new_col_1 after the original first regression and another column new_col_2 after the second regression, how can I do this?