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
Get words from a list if they contain a given substringI have a set of filenames in a list like Code: local files "a.dat b.dat c.dat d.xlsx e.dat f.xlsx"…
Unified preference configuration file across nodes on unix systemI'm using Stata 16 MP GUI with a network license on RHEL. I am connected to that system using MobaXt…
Difference in Difference SignificanceHi all, I'm trying to figure out whether there has been a change in the ratio of liquid assets to t…
Diff-in-diff and parallel trend assumptionThis question is not strictly related to Stata, I will remove if it is inappropriate. In a diff-in-…
Empty string in macroIs there any way to get an empty string recognized as a word in a macro? The idea is a macro (call i…
Subscribe to:
Post Comments (Atom)
0 Response to Loop for sum with prefix-suffix variables
Post a Comment