1

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"

1 Answer 1

3

You need to initialise a string variable with an empty string "" not . -- which is numeric missing. Otherwise you will get an error message type mismatch.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.