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!
Related Posts with Loop for sum with prefix-suffix variables
comparing the parametric survival regression modelsWhat is the command for comparing the parametric survival regression models? For example, I estimate…
Generating dummy observations to balance a panelI hope this request makes sense, as it is just to aid in my estimation. Below is the dataex of a dum…
PPML - generating a time dependent thresholdDear Stata community, I am working with a gravity model and what to cluster my observations dependi…
How to inform readers the context of hierarchical logistic regression that removes significant main effectsHello all, I'm examining a hypothetical scenario to determine how living alone and the mechanism of…
Dummy for export-starters and non-exporters in the period just before the export-starter enters the export marketI want to create a dummy for export starters to non-exporters in the years before entry. How can I c…
Subscribe to:
Post Comments (Atom)
0 Response to Loop for sum with prefix-suffix variables
Post a Comment