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
lrtestHello, I have three variables and want to see if it is worth including all of them in the model or …
Threshold regression model for cross-sectional dataHello everyone! I am planning to run a threshold regression model for a cross-sectional data. Howeve…
mofd and twoway connected graph issueHello, I use Stata 14.2. I am working on a cross-sectional dataset. I have used the command mofd to…
Prediction for discrete-time frailty models with normal heterogeneity (xtcloglog)Dear Statalist. I have estimated a discrete-time hazard model with a normal unobserved heterogeneit…
matching the x/y coordinates of flats/houses to a environmental noise mapMy aim is to match the x/y coordinates of flats to a environmental noise map. The latter is segmente…
Subscribe to:
Post Comments (Atom)
0 Response to generate a variable with if condition
Post a Comment