Hi,
I want to use 2 foreach. Basically, I want to get age of the specific person(self_age) in (varlist1) from the varlist2 of the specific person (var1==1).
But, I am not getting all the age in the rows. Is the multiple foreach working?
gen self_age=.
foreach var1 of varlist age_a age_b age_c age_d {
foreach var2 of varlist name_code_a name_code_b name_code_c name_code_d {
replace self_age= `var1' if `var2'==1
}
}
The problem is it is replacing the age of ONLY "age_d" and "name_code_d" and others are replacing as ".". How can I can fix it not replacing the first ages.
I want to use 2 foreach. Basically, I want to get age of the specific person(self_age) in (varlist1) from the varlist2 of the specific person (var1==1).
But, I am not getting all the age in the rows. Is the multiple foreach working?
gen self_age=.
foreach var1 of varlist age_a age_b age_c age_d {
foreach var2 of varlist name_code_a name_code_b name_code_c name_code_d {
replace self_age= `var1' if `var2'==1
}
}
The problem is it is replacing the age of ONLY "age_d" and "name_code_d" and others are replacing as ".". How can I can fix it not replacing the first ages.
Comment