Dear all,
I would like to create a loop for my gender variable that goes from 1 to 20. In this loop I would like to clone these 20 gender variables and recode them 1 and 0 (1 for female, 0 for male).
You can see the code I wrote below. However, when I run this Stata says 'variable ch_gender_1 already defined'. I don't know what it means. Can you maybe see where I do mistakes in the code?
Thanks in advance!
foreach var of varlist ch_gender_1- ch_gender_20 {
clonevar `var' = clone_`var'
recode clone_`var' = (2=1) (1=0)
label define clone_`var' 1 "Female" 0 "Male"
}
I would like to create a loop for my gender variable that goes from 1 to 20. In this loop I would like to clone these 20 gender variables and recode them 1 and 0 (1 for female, 0 for male).
You can see the code I wrote below. However, when I run this Stata says 'variable ch_gender_1 already defined'. I don't know what it means. Can you maybe see where I do mistakes in the code?
Thanks in advance!
foreach var of varlist ch_gender_1- ch_gender_20 {
clonevar `var' = clone_`var'
recode clone_`var' = (2=1) (1=0)
label define clone_`var' 1 "Female" 0 "Male"
}
Comment