7 November 2011

Standardise Country Names For Stata Data

If you regularly put together data sets for cross-country analysis, you'll probably know that it's a real pain to standardise country names so that you can merge together files from different sources.

For example, you want to merge two data sets: A and B. In data set A the country Bosnia and Herzegovina is referred to as "Bosnia-Hertz" and in B it is called "Bosnia-Herzegovina". To merge them into one file that you can use for data analysis you have to find this discrepancy and then change at least one of the names so that they both are the same. This is really tedious to do across multiple data sets with tens or hundreds of countries.

Over the years I've created a Stata Do-file that standardises country names and attaches their IMF country codes. You can find the file here

It clearly only standardises country name variations that I've come across. An easy way to check if a country name has not been standardised is to see if the do-file did not attach an IMF country code, i.e. use the Stata code:

list country if imfcode == .

Hopefully this will save people some time. 

If you use my do-file please cite this blog post. Also, feel free to suggest additions/changes.

No comments: