hi this is my code:
reg_table <- function(outcome) {
reg_1 <- feols(data = cat, !!sym(outcome) ~ treated)
reg_2 <- feols(data = cat, !!sym(outcome) ~ treated | color) }
export <- reg_table("happiness")
export <- reg_table("income")
I get the following error:
error in feols(data = cat, !!sym(outcome) ~ treated) :
the variable outcome is in the LHS of the formula but not in the data set
I do 100% have the "happiness" and "income" variables in the"cat" data frame. The code works without !!sym(outcome).
My goal is: within the function, !!sym(outcome)
to dynamically specify the dependent variable in the regression formula. I have to do this for many dependent variables and have more models than I have shared above, so this seems to be the most efficient way to do this. Any advice here would be so helpful.