Dear all,

I would like to run a regression for three different (dependent) variables in a loop, which looks as follows:

Code:
foreach v of varlist var1 var2 var3 {
reghdfe `v' i.post##i.Treatment##i.young `ind_controls', cluster(district) absorb(district)
outreg2 using "test.doc", append ctitle(`v')
Importantly, I want another variable in the regression to take different values, depending on the respective varlist variable.
More precisely, I have two age groups, say, "young1" and "young2". I want to use age group "young1" for the first two variables of my loop (var1 and var2) and age group "young2" for the third variable (var3).

I was wondering if it is possible to run all this in a single loop?
For me it is important that the variable name ("i.young") is the same for both age groups, such that the results are stored in the same row in the doc that is created with outreg.

I first tried something like this (where young1 and young2 are my pre-defined age cohorts):

Code:
foreach v of varlist var1 var2 var3 {

gen young=.
replace young=young1 if `v'==var1 | `v'==var2
replace young=young2 if `v'==var3

reghdfe `v' i.post##i.Treatment##i.young `ind_controls', cluster(district) absorb(district)
outreg2 using "test.doc", append ctitle(`v')
drop young
Any help would be appreciated. Thanks in advance,
Till