Learn R Programming

staggR (version 0.1.1)

select_terms: Retrieve a list of interaction terms from a sdid model to be passed on for aggregation

Description

Retrieve a list of interaction terms from a sdid model to be passed on for aggregation

Usage

select_terms(sdid, coefs = NULL, selection = NULL)

Value

character vector

Arguments

sdid

A sdid object

coefs

Optional list of specific terms from mdl to be selected

selection

List object containing values for named elements cohorts, times, and tsi. cohorts contains a character vector of cohort levels to include in the term selection; times contains a character vector of time period levels to include in the term selection; and tsi contains a vector of integers representing the number of units of time relative to each cohort's intervention to include in the term selection. If cohorts is omitted, all available cohorts will be selected. One of times or tsi must be specified. If both are specified, times is ignored.

Examples

Run this code
# Fit a staggered difference-in-differences model
sdid_hosp <- sdid(hospitalized ~ cohort + yr + age + sex + comorb,
                          df = hosp,
                          intervention_var  = "intervention_yr")

# Select coefficients corresponding to all intervention cohorts in 2018
terms_2018 <- select_terms(sdid = sdid_hosp,
                                  selection = list(times = "2018"))
terms_2018

# Pass the set of coefficients to `ave_coeff` to aggregate the effect of the
# intervention
ave_coeff(sdid_hosp, coefs = terms_2018)

# Select coefficients corresponding to added risk of hospitalization associated with
# the intervention in the year 2018, but only for the first two cohorts (5 and 6)
terms_2018_cohorts56 <- select_terms(sdid = sdid_hosp,
                                     selection = list(cohorts = c("5", "6"),
                                                      times = "2018"))

# Pass the set of coefficients to `ave_coeff` to aggregate the effect of the
# intervention
ave_coeff(sdid_hosp, coefs = terms_2018_cohorts56)

Run the code above in your browser using DataLab