library(tibble)
library(lubridate)
mhdt <- tribble(
~MHSTDTC,
"2019-07-18T15:25:40",
"2019-07-18T15:25",
"2019-07-18",
"2019-02",
"2019",
"2019---07",
""
)
# Create ASTDT and ASTDTF
# No imputation for partial date
derive_vars_dt(
mhdt,
new_vars_prefix = "AST",
dtc = MHSTDTC
)
# Create ASTDT and ASTDTF
# Impute partial dates to first day/month
derive_vars_dt(
mhdt,
new_vars_prefix = "AST",
dtc = MHSTDTC,
highest_imputation = "M"
)
# Impute partial dates to 6th of April
derive_vars_dt(
mhdt,
new_vars_prefix = "AST",
dtc = MHSTDTC,
highest_imputation = "M",
date_imputation = "04-06"
)
# Create AENDT and AENDTF
# Impute partial dates to last day/month
derive_vars_dt(
mhdt,
new_vars_prefix = "AEN",
dtc = MHSTDTC,
highest_imputation = "M",
date_imputation = "last"
)
# Create BIRTHDT
# Impute partial dates to 15th of June. No Date Imputation Flag
derive_vars_dt(
mhdt,
new_vars_prefix = "BIRTH",
dtc = MHSTDTC,
highest_imputation = "M",
date_imputation = "mid",
flag_imputation = "none"
)
# Impute AE start date to the first date and ensure that the imputed date
# is not before the treatment start date
adae <- tribble(
~AESTDTC, ~TRTSDTM,
"2020-12", ymd_hms("2020-12-06T12:12:12"),
"2020-11", ymd_hms("2020-12-06T12:12:12")
)
derive_vars_dt(
adae,
dtc = AESTDTC,
new_vars_prefix = "AST",
highest_imputation = "M",
min_dates = exprs(TRTSDTM)
)
# A user imputing dates as middle month/day, i.e. date_imputation = "mid" can
# use preserve argument to "preserve" partial dates. For example, "2019---07",
# will be displayed as "2019-06-07" rather than 2019-06-15 with preserve = TRUE
derive_vars_dt(
mhdt,
new_vars_prefix = "AST",
dtc = MHSTDTC,
highest_imputation = "M",
date_imputation = "mid",
preserve = TRUE
)
Run the code above in your browser using DataLab