
Add Atypical First-Ranked Food Source Dummy Variable
Source:R/add_food_source_atypical_d.R
add_food_source_atypical_d.RdCreates a binary (1/0/NA) dummy variable indicating whether a
household's first-ranked (main) food source is atypical/emergency. The
first-ranked source is taken from the ranked food-source question
(fsl_source_food_ranked), whose value is an ordered, space-separated list
of choice names.
Usage
add_food_source_atypical_d(
df,
source_food = "fsl_source_food_ranked",
atypical = c("hunting", "gathering", "exchange", "borrow", "gift", "begging"),
non_atypical = c("own_production", "purchase_cash", "purchase_credit",
"assistance_in_kind", "assistance_cva"),
undefined = c("other", "dnk", "pnta"),
rank_sep = " "
)Arguments
- df
A data frame of household-level data.
- source_food
Column name for the ranked food-source question. Its value is an ordered, space-separated list of choice names; the first entry is the household's main food source.
- atypical
Character vector of choice names for atypical/emergency food sources. The dummy is
1when the first-ranked source is in this set. Must not overlapnon_atypicalorundefined.- non_atypical
Character vector of known, valid non-atypical food sources. The dummy is
0when the first-ranked source is in this set. Must not overlapatypicalorundefined.- undefined
Character vector of non-substantive responses (e.g.
other,dnk,pnta). The dummy isNAwhen the first-ranked source is in this set, and also when it is missing.- rank_sep
Separator between ranked choices in
source_food. Default" ".
Value
A data frame with additional columns:
fsl_food_source_main: The first-ranked (main) food source, or
NAwhen missing.fsl_food_source_atypical_d: 1 if the first-ranked food source is atypical; 0 if it is a known non-atypical source;
NAif it cannot be classified.
Examples
df <- data.frame(
fsl_source_food_ranked = c(
"hunting purchase_cash",
"purchase_cash own_production",
"other purchase_cash",
NA
)
)
add_food_source_atypical_d(df)
#> fsl_source_food_ranked fsl_food_source_main fsl_food_source_atypical_d
#> 1 hunting purchase_cash hunting 1
#> 2 purchase_cash own_production purchase_cash 0
#> 3 other purchase_cash other NA
#> 4 <NA> <NA> NA