Skip to content

Instantly share code, notes, and snippets.

@alekrutkowski
Created September 20, 2024 13:37
Show Gist options
  • Save alekrutkowski/20e82f7f948e3581afafa62d527cbc2c to your computer and use it in GitHub Desktop.
Save alekrutkowski/20e82f7f948e3581afafa62d527cbc2c to your computer and use it in GitHub Desktop.
# Code generated with eurodata_codegen on 2024-09-18 16:26:27 (UTC+2:00, Central European Summer Time)
library(magrittr)
library(data.table)
library(eurodata)
library(openxlsx2)
dt__lfsi_emp_a <-
## Link to filtered raw data (TSV):
# https://ec.europa.eu/eurostat/api/dissemination/sdmx/2.1/data/LFSI_EMP_A/.EMP_LFS.T.Y20-64.PC_POP.EU27_2020?format=TSV
## Meaning of the codes in `filters` below:
# age=Y20-64 -- Age class = From 20 to 64 years
# geo=EU27_2020 -- Geopolitical entity (reporting) = European Union - 27 countries (from 2020)
# indic_em=EMP_LFS -- Employment indicator = Total employment (resident population concept - LFS)
# sex=T -- Sex = Total
# unit=PC_POP -- Unit of measure = Percentage of total population
## Warning: importData() below may return an empty data.frame (with 0 observations)
## if the application of `filters` results in no available data!
importData("lfsi_emp_a", # Employment and activity by sex and age - annual data
filters = list(age = c("Y20-64"),
geo = c("EU27_2020"),
indic_em = c("EMP_LFS"),
sex = c("T"),
TIME_PERIOD = c(""),
unit = c("PC_POP"))) %>%
`if`(nrow(.)==0,stop("\n",deparse1(substitute(.)),"\nreturned empty data.frame!",call.=FALSE),.) %>%
as.data.table() %>%
.[!is.na(value_)] %>%
.[, freq := NULL] %>% # not needed
.[, value_ := as.numeric(value_)] %>%
.[, flags_ := NULL] %>% # flags not needed
.[, TIME_PERIOD := TIME_PERIOD %>% as.character %>% as.integer] %>%
dcast(geo + TIME_PERIOD ~ age + indic_em + sex + unit,
fun.aggregate=identity, value.var="value_",
fill=NA_real_, sep=" ")
dt__OECD.ELS.SAE <-
fread(paste0('https://sdmx.oecd.org/public/rest/data/OECD.ELS.SAE,DSD_LFS@DF_LFS_INDIC,',
'/GBR+USA+JPN.EMP_RATIO.PT_POP_SUB._T.Y20T64.EMP',
'?startPeriod=2010&dimensionAtObservation=AllDimensions&format=csvfilewithlabels')) %>%
.[, TIME_PERIOD := TIME_PERIOD %>% as.character %>% as.integer] %>%
dcast(REF_AREA + TIME_PERIOD ~ AGE + MEASURE + LABOUR_FORCE_STATUS + SEX + UNIT_MEASURE,
fun.aggregate=identity, value.var="OBS_VALUE",
fill=NA_real_, sep=" ")
EU_data <-
dt__lfsi_emp_a %>%
copy %>%
setnames(colnames(.) %>% setdiff(c('geo','TIME_PERIOD')),
'EU') %>%
.[, geo := NULL]
Other_data <-
dt__OECD.ELS.SAE %>%
copy %>%
setnames(colnames(.) %>% setdiff(c('REF_AREA','TIME_PERIOD')),
'value_') %>%
dcast(TIME_PERIOD ~ REF_AREA,
fun.aggregate=identity, value.var="value_",
fill=NA_real_, sep=" ")
Final_table<-
merge(EU_data, Other_data, by='TIME_PERIOD') %>%
.[, EU_2030_Target := 78] %T>%
write_xlsx('Adult employment rate.xlsx')
shell('open "Adult employment rate.xlsx"')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment