Skip to content

Instantly share code, notes, and snippets.

@nacnudus
Created November 16, 2017 17:57
Show Gist options
  • Save nacnudus/deaa9fa600f4239958dd862aab49f370 to your computer and use it in GitHub Desktop.
Save nacnudus/deaa9fa600f4239958dd862aab49f370 to your computer and use it in GitHub Desktop.
Bind the UK Civil Service Staff Survey 2017 to the GOV.UK register of government organisations
#' Match the Civil Service People Survey to the government-organisation register
library(tidyverse)
library(RegistersClientR)
#' Download the survey and the register
survey_path <- "https://www.gov.uk/government/uploads/system/uploads/attachment_data/file/659571/Civil_Service_People_Survey_2017_All_Organisation_Scores__CSV_.csv"
survey <- read_csv(survey_path)[, 1:5]
govorg <-
rr_records("government-organisation") %>%
select(name, `government-organisation`)
#' Attempt to match them by name
both_dep <- inner_join(survey, govorg, by = c("Department_group" = "name"))
only_survey_dep <- anti_join(survey, govorg, by = c("Department_group" = "name"))
both_org <- inner_join(survey, govorg, by = c("Organisation" = "name"))
only_survey_org <- anti_join(survey, govorg, by = c("Organisation" = "name"))
#' 94 of them match a gov-org record by name.
both_both <-
bind_rows(both_dep, both_org) %>%
distinct()
#' 15 don't match gov-org by name exactly.
#' But they're all there if you look, except for the NS&I, which is in
#' the public-body register under its pre-2002 name "National Savings Bank".
neither <-
anti_join(survey, both_both, by = c("Department_group", "Organisation")) %>%
arrange(Organisation) %>%
mutate(`government-organisation` = c(
"PB28",
"D98",
"OT495",
"D5",
"EA42",
"EA73",
"OT281",
"EA1213",
"D69",
"EA63",
"D18",
"D18",
"D18",
"public-body:3352",
"D23;D20;D24;D19"
))
neither
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment