Recode medication variables for cycles 3-6 (long format)
Source:R/medications-recode.R
recode_meds_cycles3to6.RdRecodes medication variables from cycles 3-6 long-format data (one row per
medication per respondent), aggregates to one row per respondent, and merges into the
main cycle dataset. Wraps recodeflow::rec_with_table() and aggregate_meds_by_person().
Usage
recode_meds_cycles3to6(
data,
meds_data,
variables,
by = "clinicid",
meds_database_name = NULL,
variable_details = chmsflow::variable_details
)Arguments
- data
data.frame Main cycle data to merge medication variables into.
- meds_data
data.frame Long-format medication data (cycles 3-6) with columns
clinicid,meucatc, andnpi_25b.- variables
character Medication variable names to derive (e.g.,
"any_htn_med").- by
character Respondent identifier column. Default is
"clinicid".- meds_database_name
character Name of the meds database in
variable_details. Defaults to the name of themeds_dataargument. Override when passing a transformed object (e.g.,head()).- variable_details
data.frame Variable details table. Defaults to
chmsflow::variable_details.
Value
data.frame data with derived medication variables merged in as numeric columns.
Examples
result <- recode_meds_cycles3to6(
cycle3,
cycle3_meds,
c("any_htn_med", "diab_med")
)
#> Warning: is missing from variable details therefore cannot be recoded
head(result[, c("clinicid", "any_htn_med", "diab_med")])
#> clinicid any_htn_med diab_med
#> 1 1 1 1
#> 2 2 1 1
#> 3 3 1 1
#> 4 4 1 1
#> 5 5 1 1
#> 6 6 1 1