Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Conversion country names to country code iso3

    Hi everyone

    As written in the title, I have two different databases about countries that I would like to merge. However, the first one has country codes (iso3) and the second one uses the english names of countries.
    How can I convert quickly the countries names to iso3 please ?

    Thank you in advance,
    KF

  • #2
    Hey Kilian,
    you will first need to merge a match table.

    Download the match from: http://unstats.un.org/unsd/tradekb/K...e/Country-Code
    and save it in a file. I assume you are familiar with the merge command. Merge it to either of your datasets and then merge the other dataset using the other variable of course.

    Should be no problem

    Best,

    Comment


    • #3
      Hi Jannic,

      Thank you for your rapid answer
      I was looking at this webpage but there is no link to download the base in .dta. Do you suggest to download it on pdf ? But then how can i convert it on .dta ?
      It may be straightforward but i've never used a pdf database before

      Thank you again for your answer,
      KF

      Comment


      • #4
        Hi,

        On the webpage Jannic Cutura helpfully sent, there is a file of the country names and appropriate codes in JSON format (JavaScript Object Notation). A user simply needs to download that JSON file, import the file into Stata and unpack it into readable data.

        Save the JSON file on your computer. Then:

        To import the JSON file, use
        Code:
        import delimited C:\Users\bchartock\Desktop\reporterAreas.json, delimiter(tab) clear
        where the file path is substituted to the computer location where you saved the JSON file.

        Next, clean out the "extra" formatting text, such as quotations and commas and colons and brackets:
        Code:
        rename v1 code
        generate country = code[_n+1]
        keep if strpos(code,"id")>0
        
        foreach x in `"""' : , id text {
             foreach var in code country {
                    replace `var' = subinstr(`var',`"`x'"',"",.)
              } 
        }
        you're left with the data you're looking for!

        Ben

        Comment


        • #5
          You may also find it useful to search kountry and follow links for help implementing these sorts of linkages

          Comment


          • #6
            Thank you for your help

            Comment


            • #7
              Hello Benjamin and Janic, I was trying to do so as you said. But the following message appers:

              variable countryname does not uniquely identify observations in the master
              data

              Click image for larger version

Name:	Capture_merge.JPG
Views:	2
Size:	34.7 KB
ID:	1432622
              Attached Files

              Comment


              • #8
                The link to the json file is outdated.
                __________________________________________________ __________

                Cheers, Felix
                Stata Version: MP 18.0
                OS: Windows 11

                Comment

                Working...
                X