vincentarelbundock / countrycode

R package: Convert country names and country codes. Assigns region descriptors.
https://vincentarelbundock.github.io/countrycode
GNU General Public License v3.0
346 stars 84 forks source link

UK no more member of EU #359

Closed fciarniello closed 1 week ago

fciarniello commented 3 months ago

Under source eu28 it seems that GB is already EU member. It's wrong GB exit from EU - starting from 31 Jan 2020.

Furthermore it sholud be usefull to have the date range validity for country and region information. For example Poland is part of EU starting from 2004 before that date it was not.

cjyetman commented 3 months ago

Technically, the eu28 code is documented (?countrycode::codelist or here) as:

Member states of the European Union (as of December 2015), without special territories

As the EU currently has only 27 member countries, updating the eu28 codelist to remove UK and thereby only having 27 countries in it probably doesn't make a whole lot of sense.

EU28 was a commonly used abbreviation for the EU as it was "from the accession of Croatia in 2013 to the withdrawal of the United Kingdom in 2020".

If you're trying to determine if a country in a vector is currently a member of the EU (e.g. below example) then I'd suggest this is probably not the appropriate tool / is "off-brand" usage.

library(countrycode)

data <- data.frame(countries = c("United Kingdom", "Germany", "USA"))

data$is_eu_member <- !is.na(countrycode(countries, "country.name", "eu28"))

data
#>        countries is_eu_member
#> 1 United Kingdom         TRUE
#> 2        Germany         TRUE
#> 3            USA        FALSE
cjyetman commented 1 week ago

Having said the above, one can achieve the above using the custom_match argument to set "United Kingdom" to NA...

library(dplyr)
library(countrycode)

countrycode(
  sourcevar = c("United Kingdom", "Germany"),
  origin = "country.name",
  destination = "eu28",
  custom_match = c("United Kingdom" = NA),
  warn = FALSE
)
#> [1] NA   "EU"

data <- data.frame(countries = c("United Kingdom", "Germany", "USA"))

data$is_eu_member <- !is.na(countrycode(data$countries, "country.name", "eu28", custom_match = c("United Kingdom" = NA), warn = FALSE))
data
#>        countries is_eu_member
#> 1 United Kingdom        FALSE
#> 2        Germany         TRUE
#> 3            USA        FALSE

data %>%
  mutate(
    is_eu_member = !is.na(countrycode(data$countries, "country.name", "eu28", custom_match = c("United Kingdom" = NA), warn = FALSE))
  )
#>        countries is_eu_member
#> 1 United Kingdom        FALSE
#> 2        Germany         TRUE
#> 3            USA        FALSE

closing