Thursday, January 30, 2020

Stata Tip: Create a String Variable from a Numerical Variable's Labels

Maybe I should have known about this command. Maybe I did know it at some point in my life. Either way I re-discovered it recently so I thought I'd share it. 

Here's the situation. Imagine you're using one data set with a variable called, let's say "country of birth," with numeric codes for the different countries and then labels with the  names of the actual countries. Now let's say that you want to merge GDP data for these countries but that other data set lists countries by name, not numerical code. How do you quickly create a new variable in the original data set with the name of the country? Easy! Just use the decode command in Stata! You're welcome. 

No comments:

Post a Comment