Calculate person type classification
calc_person_type.RdAssigns each survey respondent to an analytic person type category (e.g., Full-time worker, K12 Student, Retired). This function applies a consistent set of rules based on reported age, employment status, school enrollment, and student status. It is designed to be flexible across different survey instruments by using regex-based matching of value labels.
Arguments
- persons
data.table A table of person-level records containing at least:
person_id(unique identifier)age(coded as in the survey)employment(employment code)school_type(school enrollment type code)student(student status code).
- value_labels
data.table A lookup table of value labels with columns
variable,value, andlabel. Used to flexibly map questionnaire-specific codes to common categories.
Value
data.table A table with columns:
person_idperson_type(assigned analytic category as described above).
Details
The classification is hierarchical:
Preschool child: Persons enrolled in preschool/daycare or under age 5.
University student: Persons enrolled in college, graduate school, or technical school.
K12 Student: Persons enrolled in elementary, middle, or high school.
Retired: Adults age 65+ who are not in the labor force and not students.
Non-working adult: Adults not employed, not students, and not retired (includes stay-at-home adults, those on leave or furlough, and unemployed).
Part-time worker: Adults employed part-time or as unpaid volunteers/interns.
Full-time worker: Adults employed full-time or self-employed.
Non-determined: Respondents who do not fit into the above categories (e.g., non-related household members).
Employment categories are matched using regex keywords in the value labels:
"full" → full-time
"part" → part-time
"self" → self-employed
"volunteer" or "intern" → volunteer/intern
"unemployed" → unemployed
"not employed", "retired", "stay", "leave", "furlough" → non-working
School categories are matched using regex:
"preschool" or "daycare" → Preschool child
"elementary", "middle", "high" → K12 Student
"college", "grad", "university", "technical" → University student
Examples
if (FALSE) { # \dontrun{
persons <- fetch_hts_table("person", settings)
value_labels <- fetch_hts_table("value_labels", settings)
person_type_dt <- calc_person_type(persons, value_labels)
} # }