Announcement

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

  • Getting 3 letter country codes with Kountry

    Hello. I am trying to match the country names with the 3 letter country codes. I used Kountry to get NAMES_STD. Now I need to assign a 3 letter code to each standard names. I tried various options from the help Kountry file but I was unsuccessful.

    Please advise.
    Thank you.

    CODE]
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str29 country str7 var6 str8 var7 str7 var8 str10(var27 var28) str25 NAMES_STD
    "Geography" "1995" "1996" "1997" "2016" "2017" "geography"
    "Asia Pacific" "-" "-" "1.321" "2.600" "2.309" "asia pacific"
    "Afghanistan" "-" "-" "-" "9.029" "7.573" "afghanistan"
    "Armenia" "-16.943" "-18.222" "-19.345" "-0.958" "-1.258" "armenia"
    "Azerbaijan" "-13.155" "-25.909" "-23.118" "-3.708" "4.150" "azerbaijan"
    "Bangladesh" "-2.403" "-2.503" "-1.618" "0.261" "-2.247" "bangladesh"
    "Bhutan" "15.564" "14.723" "5.052" "-30.266" "-22.078" "bhutan"
    "Brunei Darussalam" "22.000" "23.888" "21.049" "12.896" "16.359" "brunei darussalam"
    "Cambodia" "-4.895" "-7.044" "1.307" "-8.659" "-8.145" "cambodia"
    "China" "-" "-" "3.844" "1.703" "1.533" "china"
    "Fiji" "-1.573" "0.893" "-2.871" "-3.550" "-6.650" "fiji"
    end
    [/CODE]
    ------------------ copy up to and including the previous line ------------------

    Listed 11 out of 11 observations


  • #2
    Yes, -kountry- can be a little confusing. You made a mistake by retaining the variable NAMES_STD but dropping _ISO3N_. So go back to the beginning:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str29 country str7 var6 str8 var7 str7 var8 str10(var27 var28)
    "Geography"         "1995"    "1996"    "1997"    "2016"    "2017"   
    "Asia Pacific"      "-"       "-"       "1.321"   "2.600"   "2.309"  
    "Afghanistan"       "-"       "-"       "-"       "9.029"   "7.573"  
    "Armenia"           "-16.943" "-18.222" "-19.345" "-0.958"  "-1.258"
    "Azerbaijan"        "-13.155" "-25.909" "-23.118" "-3.708"  "4.150"  
    "Bangladesh"        "-2.403"  "-2.503"  "-1.618"  "0.261"   "-2.247"
    "Bhutan"            "15.564"  "14.723"  "5.052"   "-30.266" "-22.078"
    "Brunei Darussalam" "22.000"  "23.888"  "21.049"  "12.896"  "16.359"
    "Cambodia"          "-4.895"  "-7.044"  "1.307"   "-8.659"  "-8.145"
    "China"             "-"       "-"       "3.844"   "1.703"   "1.533"  
    "Fiji"              "-1.573"  "0.893"   "-2.871"  "-3.550"  "-6.650"
    end
    
    
    kountry country, from(other) stuck
    rename _ISO3N_ ncountry
    kountry ncountry, from(iso3n) to(iso3c)

    Comment


    • #3
      Thank you Clyde. There is no way I would have been able to figure this out.

      Comment

      Working...
      X