Skip to content

Instantly share code, notes, and snippets.

@timriffe
Created November 17, 2023 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timriffe/ee6901363c1850691bd03e0c78c7614d to your computer and use it in GitHub Desktop.
Save timriffe/ee6901363c1850691bd03e0c78c7614d to your computer and use it in GitHub Desktop.
Check JPN old age mort using census denominators
library(tidyverse)
pop <- read_csv("Data/JPNpop.csv")
Exp <-
pop |>
filter(Type == "C",
Year > 1970,
Age != "TOT") |>
select(Sex, Year, Age, Population) |>
group_by(Sex, Year) |>
mutate(UNK = ifelse(any(Age == "UNK"), Population[Age == "UNK"], 0)) |>
filter(Age != "UNK") |>
mutate(Population = Population + Population / sum(Population) * UNK) |>
ungroup() |>
mutate(Age = as.integer(Age))
deaths <-
read_csv("Data/JPNdeaths.csv")|>
filter(LDB == 1,
Year > 1970) |>
group_by(Sex, Year, Age) |>
summarize(Deaths = sum(Deaths)) |>
select(Sex, Year, Age, Deaths) |>
mutate(Year = as.integer(Year)) |>
group_by(Sex, Year) |>
mutate(UNK = Deaths[Age == "UNK"]) |>
filter(Age != "UNK") |>
mutate(Deaths = Deaths + Deaths / sum(Deaths) * UNK) |>
ungroup() |>
select(-UNK) |>
mutate(Age = as.integer(Age))
test <-
left_join(Exp, deaths, by = join_by(Sex, Year, Age))
test |>
mutate(Mx = Deaths / Population) |>
filter(between(Age, 90,99)) |>
ggplot(aes(y = Mx, x = Year, color = Age, group = Age)) +
geom_line() +
facet_wrap(~Sex) +
labs(title = "Mx ages 90-99 also show a breakpoint in 2000 when using census denominators")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment