Hello! I am trying to apply a series of codes to only certain observations in my dataset, conditional on country name. For each country in my dataset, I have about 60 lines of code specific to each country. Is there a way to have a series of codes only run on a subset of the observations conditional on value? I'm trying to see if rather than typing ( if country=="US") for each line of the code, I can apply it to several lines of code, almost like a loop. I tried to explore the if/else commands, but those didn't seem to work (I didn't have a command following 'else', as I didn't want any edits to be made in that section of code if country!="US".) I applied some sample code.
replace test =10 if v00 == 1 if country=="US"
replace test =30 if v00 == 2 if country=="US"
replace test =75 if v00 == 3 if country=="US"
....
replace test =43 if v00 == 1 if country=="Canada"
replace test =25 if v00 == 2 if country=="Canada"
replace test =66 if v00 == 3 if country=="Canada"
Many thanks,
Brooke
replace test =10 if v00 == 1 if country=="US"
replace test =30 if v00 == 2 if country=="US"
replace test =75 if v00 == 3 if country=="US"
....
replace test =43 if v00 == 1 if country=="Canada"
replace test =25 if v00 == 2 if country=="Canada"
replace test =66 if v00 == 3 if country=="Canada"
Many thanks,
Brooke
Comment