data-raw/gl_reg_deaths.R

library(dplyr)
library(assertr)

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

gl_reg_deaths <- pxweb_nonbirths %>%
    filter(event == "Death") %>%
    mutate(age = time - cohort - (triangle == "Upper")) %>%
    mutate(is_valid_age = !is.na(age) & (age >= 0)) %>%
    verify(is_valid_age | (count == 0L)) %>%
    filter(is_valid_age) %>%
    filter(age <= max(age * (count > 0L))) %>%
    count(cohort, age, gender, time, wt = count, name = "count")

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