Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

countrycode() doesn't recognize Kosovo?

I think I found a bug or rather a missing update in the package countrycode:

library(countrycode)
testData <- data.frame(country=c(rep("Germany",3),rep("Kosovo",3)))
testData$iso3 <- countrycode(testData$country, "country.name", "iso3c")

which is problematic not only for political reasons but also because international organizations such as the IMF or the BIS do include Kosovo in their datasets. Countrycode will produce NA's here.

What do I do with this information? The iso3c should be KSV I think.

EDIT: I contacted the package maintainer who replied that until Kosovo is recognized officially, he'd rather keep it this way.

like image 208
Jakob Avatar asked Apr 25 '16 09:04

Jakob


2 Answers

You requested ISO country codes, and ISO simply has no code assigned for Kosovo. FIPS has, though:

> countrycode('Kosovo', 'country.name', 'fips104')
[1] "KV"

If you want “KSV” as the result, you could use the World Bank code instead:

> countrycode('Kosovo', 'country.name', 'wb')
[1] "KSV"
like image 174
Konrad Rudolph Avatar answered Nov 06 '22 02:11

Konrad Rudolph


If you want to convert to iso3c, but also convert Kosovo to KSV at the same time, you can use the countrycode parameter custom_match...

library(countrycode)

testData <- data.frame(country=c(rep("Germany",3),rep("Kosovo",3)))

countrycode(testData$country, "country.name", "iso3c", 
            custom_match = c(Kosovo = "KSV"))
#[1] "DEU" "DEU" "DEU" "KSV" "KSV" "KSV"
like image 2
CJ Yetman Avatar answered Nov 06 '22 03:11

CJ Yetman