I am trying in Stata to generate a variable called region_code
, based on another existing variable region
,
Essentially, I want something that looks as follows: Country region region_code
X South Asia SA
Y Latin America & Caribbean LAC
And this is the code that I have tried:
generate region_codes = .
replace region_codes = "SA" if region == "South Asia"
replace region_codes = "LAC" if region == "Latin America & Caribbean"
You need to initialise a string variable with an empty string
""
not.
-- which is numeric missing. Otherwise you will get an error messagetype mismatch
.