Dear community,
I am a real newbie to both Stata and this forum so please be patient with me and my easy question. At least I hope it is an easy one :-). I have a dataset with a string variable (names of districts) and would like to generate a new variable with the ISO codes of these districts. I found out how to generate the variable for only one of the strings:
gen district_code=102 if locationlevel2=="KAMPALA"
So now I would need to extend this by a list somehow to have something like: gen district_code=[102, 314] if locationlevel2==["KAMPALA", "ABIM"] that generates district_code that is 102 for Kampala, 314 for Abim etc. but I cannot figure out the right syntax for that. I also tried smth like gen district_code=0 and then if locationlevel2=="KAMPALA" {district_code=102} but that didn't work either.
I hope this question is understandable and easy to answer and wanna thank you in advance for your help!
Best, Tabea
Related Posts with generate a variable with if condition
Create new variable with new data in current datasetHi I have seen many posts with similar questions, but not one that I think completely fits my proble…
Clustering SE in an Instrumental Variable (IV) regression yields to negative effects compared to "unclustered" IV regression - How's that?Hello today I performed an IV regression with two instruments. Both instruments are indicator vari…
Weird errorIs there a solution to typing the following in the command line...? . set obs 1000 /*what*/ varlist…
Specification of Known Latent Classes using gsem lclassDear StataList, I am using Stata 14 on a Mac OS Yosemite 10.10.5. I am trying to use gsem to weight…
Combining coefplot with stdBetaDear all while this might sound odd, I need help with getting two packages working together. Here…
Subscribe to:
Post Comments (Atom)
0 Response to generate a variable with if condition
Post a Comment