Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed bugs in the keep population flag. #874

Merged
merged 7 commits into from
Dec 7, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions R/add_keep_population_flag.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ add_keep_population_flag <- function(individual_file, year) {
year_available <- pop_estimates %>%
dplyr::pull(year) %>%
unique()

if (calendar_year %in% year_available) {
pop_estimates <- pop_estimates %>%
dplyr::filter(year == calendar_year)
Expand Down Expand Up @@ -70,17 +71,18 @@ add_keep_population_flag <- function(individual_file, year) {
# If they don't have a locality, they're no good as we won't have an estimate to match them against.
# Same for age and gender.
nsu_keep_lookup <- individual_file %>%
dplyr::filter(gender == 1 | gender == 2) %>%
dplyr::filter(!is.na(locality), !is.na(age)) %>%
# Remove people who died before the mid-point of the calender year.
# This will make our numbers line up better with the methodology used for the mid-year population estimates.
# anyone who died 5 years before the file shouldn't be in it anyway...
dplyr::filter(death_date > mid_year | nsu != 0) %>%
dplyr::filter(death_date > mid_year | is.na(death_date) | nsu != 0) %>%
# Calculate the populations of the whole SLF and of the NSU.
dplyr::group_by(locality, age_group, gender) %>%
dplyr::mutate(
nsu_population = sum(nsu),
total_source_population = dplyr::n()
) %>%
dplyr::filter(nsu == 1) %>%
Jennit07 marked this conversation as resolved.
Show resolved Hide resolved
dplyr::left_join(pop_estimates,
by = c("locality", "age_group", "gender")
) %>%
Expand Down Expand Up @@ -137,7 +139,7 @@ add_age_group <- function(data, age_var_name) {
data <- data %>%
dplyr::mutate(
age_group = dplyr::case_when(
{{ age_var_name }} >= 0 & {{ age_var_name }} <= 4 ~ "0-4",
{{ age_var_name }} >= -1 & {{ age_var_name }} <= 4 ~ "0-4",
Jennit07 marked this conversation as resolved.
Show resolved Hide resolved
{{ age_var_name }} >= 5 & {{ age_var_name }} <= 14 ~ "5-14",
{{ age_var_name }} >= 15 & {{ age_var_name }} <= 24 ~ "15-24",
{{ age_var_name }} >= 25 & {{ age_var_name }} <= 34 ~ "25-34",
Expand Down
Loading