diff --git a/R/add_keep_population_flag.R b/R/add_keep_population_flag.R index 7b89c9b48..440772acd 100644 --- a/R/add_keep_population_flag.R +++ b/R/add_keep_population_flag.R @@ -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) @@ -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) %>% dplyr::left_join(pop_estimates, by = c("locality", "age_group", "gender") ) %>% @@ -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", {{ 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", diff --git a/run_slf_process_manually.R b/run_slf_process_manually.R index 70dba2ba4..b5f4dbbb2 100644 --- a/run_slf_process_manually.R +++ b/run_slf_process_manually.R @@ -4,16 +4,16 @@ library(createslf) --- -## UPDATE: Year you would like to run ## -year <- "2223" + ## UPDATE: Year you would like to run ## + year <- "2223" ## UPDATE: Year on "processed_data_list_XXX" ## processed_data_list <- targets::tar_read("processed_data_list_2223") --- -# Run episode file -create_episode_file(processed_data_list, year = year) %>% + # Run episode file + create_episode_file(processed_data_list, year = year) %>% process_tests_episode_file(year = year) # Run individual file