data-raw/gl_reg_popn.R

library(dplyr)
library(assertr)
library(tidyr)

pxweb_nonbirths <- readRDS("data-raw/pxweb_nonbirths.rds")

head <- pxweb_nonbirths %>%
    filter(event == "Population (start of year)") %>%
    filter(time == min(time)) %>%
    mutate(time = time - 1L) ## convert to end of year

tail <- pxweb_nonbirths %>%
    filter(event == "Population (end of year)")

gl_reg_popn <- bind_rows(head, tail) %>%
    filter(time >= cohort) %>%
    mutate(age = time - cohort) %>%
    verify(!is.na(age) & age >= 0) %>%
    count(age, gender, time, wt = count, name = "count")

save(gl_reg_popn,
     file = "data/gl_reg_popn.rda",
     compress = "xz")
ONSdigital/Bayesian-demographic-accounts documentation built on Jan. 10, 2022, 12:34 a.m.