Set Response Option (ROS) labels for variables in AmericasBarometer datasets
lpr_set_ros.Rd
This function extracts formatted response option labels for AmericasBarometer variables, using label tables stored as attributes. The labels are formatted with their corresponding numeric codes and can be pulled in multiple languages.
Arguments
- data
A data frame loaded using readstata13 containing label.table attributes.
- lang_id
Language identifier for the labels ("en" for English, "es" for Spanish, "pt" for Portuguese). Default is "en" (English).
- attribute_name
The name of the attribute where the formatted response options string will be stored. Default is "roslabel".
Details
The function looks for label tables stored as attributes of the data frame, with names following the pattern "VARNAME_lang_id" (e.g., "ing4_en" for English labels of variable ing4). Each label table should be a named numeric vector where names are the response labels and values are the corresponding codes.
Special codes (values ≥ 1000) are excluded from the response options string.
Examples
# Apply the function
if (FALSE) { # \dontrun{
bra23 <- lpr_set_ros(bra23) # Default English
bra23 <- lpr_set_ros(bra23, lang_id = "es", attribute_name = "respuestas") # Spanish
bra23 <- lpr_set_ros(bra23, lang_id = "pt", attribute_name = "ROsLabels_pt") # Portuguese
# View the resulting attribute
attr(bra23$ing4, "roslabel")
attr(bra23$ing4, "respuestas")
attr(bra23$ing4, "ROsLabels_pt")
} # }