I have regression models (OLS/IV ivreg
) which I use on different datasets and different outcomes. I use a loop to change the outcome variable, run some models and store results with modelsummary
in separate .html
files. I wonder how I could combine those, like having different panels or nested outcomes.
library(modelsummary)
library(ivreg)
data(mtcars)
models <- c("mpg", "disp", "hp")
for(i in models){
formula1 <- paste(i, "~ cyl + qsec + carb + drat")
formula2 <- paste(i, "~ cyl + qsec + carb | drat | wt")
# linear regression model
ols <- lm(formula = formula1, data = mtcars)
# instrument variable regression
iv <- ivreg(formula = formula2, data = mtcars)
modelsummary(list("OLS" = ols, "IV" = iv),
output = paste0("Outcome_", i, ".html"))
}
Result is supposed to be look something like this: