I am a beginner stata user and new to this post. I found this forum was extremely helpful when I google search for stata help.

I have 5 dependent variables and I need to run same regressions for each of the dependent variables. For each dependent variable, I will run three sets of regressions and the only difference between the three sets of regression was one set of interaction terms were using different variables. instead of running one loop for 5 dependent variables three times for each of the three interaction terms and control variables, I think a loop for 5 dependent variables and a within loop for the three interaction terms can make it easier.

Here are my codes:

local ppost t_state##ib2.p_c ---i used this to create a local variable for my interaction terms, which may be wrong

local postdum t_state##ib0.post

local state st##ib2.p_c

local pv `ppost' `postdum' `state'

foreach v of varlist b2 b4 b8 b2 b16{

foreach p of local pv{

xi:svy: reg `v' `p' $charm if r_`v'==1 & family==0

est sto nom_`v'`p'

}

}

the model run only for the first variable and the first interaction terms, which is t_state##ib2.p_c with an error message:

# invalid name

# invalid name

ib2.p_c invalid name

r(7);

I suspect that it was because I did wrong when define local for the interaction terms. I tested the following

display `pv'

invalid matrix stripe;

t_state##ib2.p_c

r(198);

Thank you very much for the help!

I have 5 dependent variables and I need to run same regressions for each of the dependent variables. For each dependent variable, I will run three sets of regressions and the only difference between the three sets of regression was one set of interaction terms were using different variables. instead of running one loop for 5 dependent variables three times for each of the three interaction terms and control variables, I think a loop for 5 dependent variables and a within loop for the three interaction terms can make it easier.

Here are my codes:

local ppost t_state##ib2.p_c ---i used this to create a local variable for my interaction terms, which may be wrong

local postdum t_state##ib0.post

local state st##ib2.p_c

local pv `ppost' `postdum' `state'

foreach v of varlist b2 b4 b8 b2 b16{

foreach p of local pv{

xi:svy: reg `v' `p' $charm if r_`v'==1 & family==0

est sto nom_`v'`p'

}

}

the model run only for the first variable and the first interaction terms, which is t_state##ib2.p_c with an error message:

# invalid name

# invalid name

ib2.p_c invalid name

r(7);

I suspect that it was because I did wrong when define local for the interaction terms. I tested the following

display `pv'

invalid matrix stripe;

t_state##ib2.p_c

r(198);

Thank you very much for the help!

## Comment