I need to run multiple estimations with feols, using sw (stepwise). Since I have many variables for the right-hand side, I would like to pass them as a vector or string with the vector elements. I must me making a beginner's mistake.
The following code works:
library(fixest)
set.seed(42)
data <- data.frame(
y = runif(100, min = 1, max = 100),
x1 = runif(100, min = 1, max = 100),
x2 = runif(100, min = 1, max = 100)
)
rm <- feols(log(y) ~ sw(log(x1), log(x2)), data=data)
summary(rm)
However, the following does not:
library(fixest)
set.seed(42)
data <- data.frame(
y = runif(100, min = 1, max = 100),
x1 = runif(100, min = 1, max = 100),
x2 = runif(100, min = 1, max = 100)
)
regressors <- c("log(x1)", "log(x2)")
regressors <- paste(regressors, collapse = ", ")
rm <- feols(log(y) ~ sw(regressors), data=data)
summary(rm)
How can I pass right-hand-side variables as a vector or string to feols?
Here is the error message:
Error in feols(log(y) ~ sw(regressors), data = data) :
The variable 'regressors' is in the RHS of the formula but not in the data set.