Lets you combine individual items from the bundled items dataset into
your own sum-score composite(s), merged into your data by state and year.
Each composite is the row-wise sum of the items you choose, computed
within a single year (you cannot mix items from different years into one
composite). To merge individual items without combining them, see
item_stigmaR().
Arguments
- df
A data frame containing your data.
- state
Character string. Name of the column in
dfcontaining two-letter state abbreviations (e.g., "IL", "CA").- year
Character vector. Years to merge in (e.g.,
c("2016", "2017")). Each custom index is computed separately for each requested year and added as a column namedYYYY_varname.- cust_index
A character vector of item names to sum into a single custom index, or a list of such character vectors to build multiple custom indices at once. Valid item names are determined automatically from the columns of the bundled
itemsdataset (everyiat_sex_*mean column, excluding theiat_sex_n_*respondent-count columns). Seenames(stigmaR::items)for the full, current list.- var_name
Character vector of names for the new column(s), one per group in
cust_index(i.e.,length(var_name)must equallength(cust_index), or be1ifcust_indexis a single vector).- na_rm
Logical. If
FALSE(default), a composite isNAfor a given state-year if any of its component items areNAfor that state-year. IfTRUE, the composite is the sum of whatever component items are non-missing (andNAonly if all are missing).
Value
The input data frame with new columns named YYYY_varname
containing the summed custom index for each requested year and
var_name.
References
Kim, S. & Todd, N. R. (2027). stigmaR: Enhancing Accessibility, Reproducibility, and Transparency of Structural Stigma Research.
Examples
if (FALSE) { # \dontrun{
# One custom index
new_df <- cust_stigmaR(
df = my_data,
state = "state_abbrev",
year = c("2016", "2017"),
cust_index = c("iat_sex_imp_d", "iat_sex_exp_therm_gm"),
var_name = "my_custom_index"
)
# Multiple custom indices at once
new_df <- cust_stigmaR(
df = my_data,
state = "state_abbrev",
year = "2016",
cust_index = list(
c("iat_sex_imp_d", "iat_sex_exp_therm_gm"),
c("iat_sex_exp_pol_marr", "iat_sex_exp_pol_legal", "iat_sex_exp_pol_adopt")
),
var_name = c("implicit_plus_therm", "policy_sum")
)
} # }