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
k-mean clustering using existing similarity matrixI have a dataset of workers, and I want to divide them into clusters based on some observables, one …
Mauchly's test of sphericity commandI am trying to test the assumption of sphericity for the purpose of running a repeated measures ANOV…
What is the correct way to use double-clustering in reghdfe?Hi all, I have a panel data set and I believe that correlations appear in two dimensions with both …
Potential Stata (MLwiN/Estout) bug - Output of Odds Ratios' Significance Levels Hi all, I think I may have inadvertently stumbled upon a bug after using the runmlwin command for …
Complicated coarsed exact matchingHi STATLIST, I am stocked into a matching problem. In particular, I would like to use coarsened exa…
Subscribe to:
Post Comments (Atom)
0 Response to generate a variable with if condition
Post a Comment