Hello,
I am trying to find a way to loop element by element operations across two lists of variables. If anyone know how to help me I would be extremely grateful.
Consider the following example. I would like to look at the effects of length and weight on prices. I know how to loop a regression changing a variable in the following way.
Code:
webuse auto2.dta,clear
* loop my regression over a list of variable
foreach var of varlist weight length{
reg price `var' turn
}
Now consider that I want to look at the effects of length and weight over a particular subgroup of observations.

Code:
* create grouping variables
gen lowweight=1
replace lowweight=0 if weight>2240
gen lowlength=1
replace lowlength==0 if length<170
* manually the regression output I would like is produced by the following regressions
reg price length turn if lowlength==1
reg price weight turn if lowweight==1
I need to do this for a two long list of variables, is there a way to do this via element-wise looping? Where my function of interest is looped over the fist element of the first list and the first elelement of the second list. The second element of the first list and the second element of the second list etc.

I have tried the following, but it loops every element of the first list over every element of the second list. Hence it is not an element-wise loop
Code:
foreach var of varlist weight length{
foreach grp of varlist lowweight lowlength{
reg price `var' turn if `grp'==1
}
}

If anyone has any suggestion on how to address this I would be immensely grateful


Thanks