library(LTASR)
library(dplyr)
#Import example person file
person <- person_example %>%
mutate(dob = as.Date(dob, format='%m/%d/%Y'),
pybegin = as.Date(pybegin, format='%m/%d/%Y'),
dlo = as.Date(dlo, format='%m/%d/%Y'))
#Import example history file
history <- history_example %>%
mutate(begin_dt = as.Date(begin_dt, format='%m/%d/%Y'),
end_dt = as.Date(end_dt, format='%m/%d/%Y'))
#Import default rate object
rateobj <- us_119ucod_19602021
#Define exposure of interest. Create exp_strata object.The `employed` variable
#indicates (0/1) periods of employment and will be summed each day of each exposure
#period. Therefore, this calculates duration of employment in days. The cut-points
#used below will stratify by person-time with less than and greater than a
#year of employment (365 days of employment).
exp1 <- exp_strata(var = 'employed',
cutpt = c(-Inf, 365, Inf),
lag = 0)
#Stratify cohort by employed variable.
py_table <- get_table_history(persondf = person,
rateobj = rateobj,
historydf = history,
exps = list(exp1))
#Multiple exposures can be considered.
exp1 <- exp_strata(var = 'employed',
cutpt = c(-Inf, 365, Inf),
lag = 0)
exp2 <- exp_strata(var = 'exposure_level',
cutpt = c(-Inf, 0, 10000, 20000, Inf),
lag = 10)
#Stratify cohort by employed variable.
py_table <- get_table_history(persondf = person,
rateobj = rateobj,
historydf = history,
exps = list(exp1, exp2))
Run the code above in your browser using DataLab