I'm trying to use sapply to regress on a number of outcome variables. The sapply function works and returns the linear models properly, BUT the Call returns '''Call: FUN(formula = X[[i]], data = ..1)'''. I believe that this is the reason that I cannot then plug the sapply output into Stargazer without getting this error:
% Error: Unrecognized object type.
I have compare the output of the sapply variable with a manual plug in for the first outcome variable. The results are the same but Stargazer won't work with the sapply version.
This works:
normal_approach <- lm(y_1~x, data = df)
stargazer(normal_approach, type = 'text')
This does not:
test_col <- c("y_1") #I have more variables but troubleshooting so removed them
names(n) <- names(test_col)
forms <- paste(test_col, '~x')
sapp_approach <- sapply(forms, lm, data = df, simplify = FALSE, USE.NAMES = TRUE)
sapply_version <- sapp_approach$`y_1~x' #confirmed that this variable is correct
stargazer(sapply_version, type = 'text')
% Error: Unrecognized object type.
The Call function in the sapply approach is the problem, I think.
Call: FUN(formula = X[[i]], data = ..1)