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
xtabond2 for a dynamic GMMHello dear al, I face a problem when I run a dynamic GMM model for a panel data. My research is abo…
Generate new variable by levelsof format %td datevar …
generating a new var and replacing its values with the previous year's valuesHi everyone, A sample of my data looks as follows (my current data ). As you can see, the person 1's…
Looping through Import Delimited command using localsHi Statalist Users, I read a text delimited file using the standard command: > import delimited…
Extended Cox model (Cox model with time-varying covariates)Dear STATALIST I would like to investigate the association of baseline treatment A (binary variable…
Subscribe to:
Post Comments (Atom)
0 Response to Loop for sum with prefix-suffix variables
Post a Comment