I'm trying to do a loop over two major variables that I will show you in the following code:
Basically, I want to do the following thing:
Rather than:
Could anyone explain me the difference between these two methods mentioned above and their diferent syntaxes please?
I'm also open to suggestions that improve my code above. Thanks for the feedback.
Michael
Code:
forvalues i = 2/4 { * local ba_hes Bachelor_hes local res_field restricted_field foreach c of local ba_hes { forvalues j = 2/5 { foreach d of local res_field { svy,subpop(`c'`i' if `d'`j' == 1):prop k_uebertritt2 } } } }
Code:
svy,subpop(Bachelor_hes2 if restricted_field2 == 1) : prop k_uebertritt2
svy,subpop(Bachelor_hes2 if restricted_field3 == 1) : prop k_uebertritt2
svy,subpop(Bachelor_hes2 if restricted_field4 == 1) : prop k_uebertritt2
svy,subpop(Bachelor_hes2 if restricted_field5 == 1) : prop k_uebertritt2
up to...
svy,subpop(Bachelor_hes4 if restricted_field5 == 1) : prop k_uebertritt2
Code:
svy,subpop(Bachelor_hes2 if restricted_field1 == 1) : prop k_uebertritt2
svy,subpop(Bachelor_hes3 if restricted_field1 == 1) : prop k_uebertritt2
svy,subpop(Bachelor_hes4 if restricted_field1 == 1) : prop k_uebertritt2
up to...
svy,subpop(Bachelor_hes2 if restricted_field5 == 1) : prop k_uebertritt2
svy,subpop(Bachelor_hes3 if restricted_field5 == 1) : prop k_uebertritt2
svy,subpop(Bachelor_hes4 if restricted_field5 == 1) : prop k_uebertritt2
I'm also open to suggestions that improve my code above. Thanks for the feedback.
Michael
Comment