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
Problem with moving average by a string variable.Hello. I have data from 1999q1 to 2019q2 for 6 different regions (string variable). Each observation…
Problem With Xtabond2 In Dynamic Panel Data Concerning Omitted Lagged Coefficients Reported in OutputDear Statalist users. I am using the xtabond2 to draw advantage of the twostep System GMM approach …
Margins with Fractional LogitDear All, I am stuck with interpreting and correct usage of margins command even after reading the …
Correlation between two vectorsDear Statalister, I am currently working with data which include patents, patent classes and year. …
Meaning and interpretation of the TestHello At the moment I'm reading a paper and came across this table, which I unfortunately don't qui…
Subscribe to:
Post Comments (Atom)
0 Response to generate a variable with if condition
Post a Comment