data-raw/pxweb_nonbirths.R

## Read data directly from Statistics Greenland website using 'pxweb'

library(pxweb)
library(dplyr)

url <- "https://bank.stat.gl/api/v1/en/Greenland/BE/BE80/BEXCALC.PX"

query <- list("year of birth" = as.character(1875:2021),
              "place of birth" = "T",
              event = c("P", "I", "O", "D", "C", "U"), ## excluding "B" for births
              gender = c("K", "M"),
              "triangles(Lexis)" = c("0", "1"),
              time = as.character(2011:2021))

pxweb_nonbirths <- pxweb_get(url = url,
                             query = query) %>%
    as.data.frame(column.name.type = "text",
                  variable.value.type = "text") %>%
    rename(cohort = "year of birth",
           triangle = "triangles(Lexis)",
           count = "Population Accounts") %>%
    filter(!is.na(count)) %>%
    filter(cohort <= time) %>%
    mutate(cohort = as.integer(cohort),
           time = as.integer(time),
           count = as.integer(count))

saveRDS(pxweb_nonbirths,
        file = "data-raw/pxweb_nonbirths.rds")
ONSdigital/Bayesian-demographic-accounts documentation built on Jan. 10, 2022, 12:34 a.m.