Hi,
I want to use 2 foreach. Basically, I want to get age of a specific person(self_age) in (varlist1) from the varlist2 of the specific person ( where var1==1).
But, I am not getting all the age in the rows with this command
The problem is it is replacing the age of ONLY "age_4" and "name_code_i" and rest all the observations are replacing as missing ".". How can I can I get self_age in one var?
I want to use 2 foreach. Basically, I want to get age of a specific person(self_age) in (varlist1) from the varlist2 of the specific person ( where var1==1).
But, I am not getting all the age in the rows with this command
Code:
gen self_age=. foreach var1 of varlist age_1 age_2 age_3 age_4 { foreach var2 of varlist name_code_a name_code_b name_code_c name_code_d name_code_e name_code_f name_code_g name_code_h name_code_i { replace self_age= `var1' if `var2'==1 } }
The problem is it is replacing the age of ONLY "age_4" and "name_code_i" and rest all the observations are replacing as missing ".". How can I can I get self_age in one var?
Comment