Calculates cause-specific death (and optionally time to death) from codes in the Cause of Death Registry.
create_deathvar(
cohortdata,
indexdate,
deathdate,
censdate,
calctimetodeath = FALSE,
name,
orsakkod,
orsakvar = ULORSAK,
valsclass = "num",
meta_reg = "Cause of Death",
meta_pos,
warnings = TRUE
)
Data containing the cohort.
Index date for the patient (usually date of admission or discharge entered into SwedeHF). Must be given if calctimetodeath = TRUE.
Vector of death dates.
Vector of dates. Deaths are allowed up until this day (usually date of death or end follow-up).
Should time to death be calculated? Default is FALSE.
Name of resulting variable (prefix is sos_out_death).
String of icd codes as a regular expression defining the cause specific death. Should preferably start with blank space " ".
Column where diakod is found. All codes should preferably start with blank space " ". Default is ULORSAK.
optional argument specifying the class of the comorbidities/outcomes. Allowed values are "num" (numeric: 1, 0), "char" (character: "Yes", "No"), "fac" (factor: "Yes", "No"). Default is "num".
Optional argument specifying registries used. Printed in metadatatable. Default is "Cause of Death".
Optional argument specifying positions used to search for deaths. Printed in metadatatable.
Should warnings be printed. Default is FALSE.
dataset with column containing cause-specifc death. Also dataset metaout that writes directly to global enviroment with information on constructed variables.
dors_data <- prep_sosdata(dors_data, registry = "dors", impute = FALSE)
rs_data <- dplyr::left_join(rs_data, dors_data, by = "id")
rs_data <- create_deathvar(
cohortdata = rs_data,
name = "cv",
orsakkod = " I"
)