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.
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"
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With