Hello,

I work with almost 2*80 variables with a prefix-suffix format like: A_CH1211, A_CH1212, A_CH1213,... and B_CH1211, B_CH1212, B_CH1213...
I need to create new variables which is the sum of A_var + B_var
Example: AB_CH1211= A_CH1211 + B_CH1211

I have tried several loops, read many docs, tried again but failed (and, at this point, see no solution).

For example, I tried these loops:

local varlist B_* A_*
foreach `var' of local varlist {
egen AB_`var'= sum(A_`var' + B_`var')
}

or

foreach var of varlist B_CH1211-A_CH2424{
gen AB_`var'= A_`var' + B_`var'
}

or worst:
foreach x in B_CH1211- A_CH2424 {
foreach y in B_CH1211-A_CH2424 {
egen AB_`y'= sum(`x'`y' + `x'`y')
}
}


Someone to help me ?
Many thanks!