From ce90a452f9db3f57560e0c777a98d01edad78af8 Mon Sep 17 00:00:00 2001 From: Megan McNicol <43570769+SwiftySalmon@users.noreply.github.com> Date: Mon, 24 Jun 2024 14:25:35 +0100 Subject: [PATCH] adding the death dates to activity after death cases (#972) adding the death dates to the cases where there is activity after death Co-authored-by: marjom02 --- R/add_activity_after_death_flag.R | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/R/add_activity_after_death_flag.R b/R/add_activity_after_death_flag.R index 0842b47ec..c6c003e3e 100644 --- a/R/add_activity_after_death_flag.R +++ b/R/add_activity_after_death_flag.R @@ -85,7 +85,7 @@ add_activity_after_death_flag <- function( flag_data <- flag_data %>% dplyr::filter(.data$activity_after_death == 1) %>% # Remove temporary flag variables used to create activity after death flag and fill in missing death_date - dplyr::select(.data$year, .data$chi, .data$record_keydate1, .data$record_keydate2, .data$activity_after_death) %>% + dplyr::select(.data$year, .data$chi, .data$record_keydate1, .data$record_keydate2, .data$activity_after_death, .data$death_date_boxi) %>% dplyr::distinct() # Match activity after death flag back to episode file @@ -94,7 +94,12 @@ add_activity_after_death_flag <- function( flag_data, by = c("year", "chi", "record_keydate1", "record_keydate2"), na_matches = "never" - ) + ) %>% + dplyr::mutate(death_date = lubridate::as_date(ifelse(is.na(death_date) & !(is.na(death_date_boxi)), + death_date_boxi, death_date + ))) %>% + dplyr::select(-death_date_boxi) + return(final_data)