Skip to contents

A helper function primarily used by table_one() to calculate a person's most recent state/province.

Approximate each patient's geographic location by calculating the state or province where each patient most commonly received care during a certain number of years preceding their most recent visit. If multiple states or provinces have the same number of visits for a patient, the state/province with the most recent visit is selected.

Usage

get_person_state_province(ds, years_of_data = 2)

Arguments

ds

A PicnicHealth dataset list object.

years_of_data

A numeric value, specifying the number of years of recent data from which the patients' most common care site state will be obtained. The default is 2 years.

Value

A data frame, one row per patient, with columns person_id, state_province (two-character state/province codes), state_region (US Census Region), and state_division (US Census Division).

Details

Beyond its use in table_one(), this function may be useful to add an additional column to an existing analytic data.frame that already contains person_id using dplyr::left_join() to include state_province. See examples.

Examples

if (FALSE) { # \dontrun{
# Add `state_province` to an analytic data set that contains `person_id`:
analytic_dataset %>%
  left_join(get_person_state_province(ds))
} # }