6

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.

CJ Yetman
  • 8,373
  • 2
  • 24
  • 56
Jakob
  • 1,325
  • 15
  • 31
  • 4
    Contact package maintainer - `Vincent Arel-Bundock ` – rbm Apr 25 '16 at 10:22
  • 2
    Kosovo is not a universally recognised country and consequently is not part of the standards: http://unstats.un.org/unsd/tradekb/Knowledgebase/Country-Code and https://www.iso.org/obp/ui/#search – James Apr 25 '16 at 10:40
  • 1
    but it shows up in universally recognized datasets which people are working with – Jakob Apr 25 '16 at 13:14
  • @rbm The package doesn’t seem to have a bug. – Konrad Rudolph May 12 '16 at 14:39
  • i think your comment was meant for @PeterPan – rbm May 12 '16 at 14:40
  • @rbm No, you suggested contacting the package maintainer … I thought your implication was that the package had a bug. – Konrad Rudolph May 12 '16 at 14:42
  • The original post ended with "What do I do with this information?" so I suggested he contacted the owner to discuss with Vincent. OP later edited the post (after he'd contacted the owner). – rbm May 12 '16 at 14:45
  • I'll still keep it undeleted for google. Others might have the same problem and now we have an answer – Jakob May 12 '16 at 14:47
  • I am the maintainer. Previous comment is correct. The ISO standard does not include a code for Kosovo. Therefore, it would be incorrect to include one in countrycode. I know that certain organizations create ad hoc codes, but those must be treated on an ad hoc basis by the analyst. A pain, I know... – Vincent Jan 25 '17 at 00:51
  • Issues can be discussed on github: https://github.com/vincentarelbundock/countrycode – Vincent Jan 25 '17 at 00:52

2 Answers2

6

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"
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
3

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"
CJ Yetman
  • 8,373
  • 2
  • 24
  • 56