Hello all, I am a new STATA user and trying to run a foreach regression loop.

I have 32 independent variables of which B C D are log transformed, E and F are categorical, and the rest are dummy variables.

I have a log transformed independent variable (ln_A) that I want to regress against various combinations of the independent variables.

The total number of observations in my dataset is 800. I am interested in obtaining the regression coefficients for each combination of variables regressed against ln_y and export the coefficients as well r2, adj_r2, and rmse into an excel file.

the code I have tried so far is as follows:

local predictors ln_B ln_C ln_D E F G H I J…etc
local regressors

foreach p of local predictors {
local regressors `regressors’ `p’
regress ln_A `regressors’
outreg2 using file, excel e(r2_a rmse)
}

This code works but for each iteration it adds another variable to the regression. Whereas, I want to randomize the combination of variables used for each iteration so it would be something like:

reg ln_A ln_B E F I J
reg lnA E K L N F
etc.

All help would be greatly appreciated!