R/create_medvar.R
create_medvar.Rd
create_medvar(
atc,
medvar = ATC,
medname,
cohortdata,
meddata,
id = "lopnr",
valsclass = "num",
fromdate,
indexdate,
metatime = "-5mo-14days"
)
String of ATC as a regular expression defining the medicine. Default is ATC.
Name of variable where ATC are found.
Name of resulting variable (with prefix sos_lm_).
Data to add medvar to.
Data where ATC codes are found.
Vector of post identifier (meds for each post). Default is lopnr.
optional argument specifying the class of the meds. Allowed values are "num" (numeric: 1, 0), "char" (character: "Yes", "No"), "fac" (factor: "Yes", "No"). Default is "num".
Optional date where post with a indexdate prior to this are set to NA (e.g. prior to start of DDR + x months).
If fromdate is given, variable were indexdate is found.
For what time span are the meds selected in data? Printed in metalm. Default text is "-5mo-14days".
cohortdata with column containing medicine. Also dataset metalm that writes directly to global enviroment with information on constructed variables.
if (FALSE) {
lmtmp <- left_join(
rsdata %>%
select(LopNr, shf_indexdtm),
lmsel,
by = "LopNr"
) %>%
mutate(diff = as.numeric(EDATUM - shf_indexdtm)) %>%
filter(diff >= -30.5 * 5, diff <= 14) %>%
select(LopNr, shf_indexdtm, EDATUM, ATC)
rsdata <- create_medvar(atc = "^C07A", medname = "bbl", cohortdata = rsdata, meddata = lmtmp, id = c("LopNr", "shf_indexdtm"))
}