I am currently working with a dataset with 250 variables and aprox. 200.000 obs.
I need to create a variable called x if the values in the varlist act1-act75 are equal to 042* or V08*, and if the values in the varlist adm1-adm75 = "yes"
I was able to run the first part using the following code:
gen x=.
foreach var of varlist act1-act75 {
replace x =1 if strmatch(`var', "042*") | strmatch(`var', "V08*")
}
replace x=0 if x==.
But when I tried both varlist, I got 0 changes (and it should be 650 obs). Here is my code:
drop x
gen x=.
foreach var of varlist act1-act75 {
foreach y of varlist adm1-adm75 {
replace x=1 if (strmatch(`var', "042*") | strmatch(`var', "V08*")) & strmatch(`y', "Yes")
}
}
replace x=0 if x==.
Please help. Thanks in advance.
Lesley.
Comment