Skip to contents

Assigns 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.

Usage

calc_person_type(persons, 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, and label. Used to flexibly map questionnaire-specific codes to common categories.

Value

data.table A table with columns:

  • person_id

  • person_type (assigned analytic category as described above).

Details

The classification is hierarchical:

  1. Preschool child: Persons enrolled in preschool/daycare or under age 5.

  2. University student: Persons enrolled in college, graduate school, or technical school.

  3. K12 Student: Persons enrolled in elementary, middle, or high school.

  4. Retired: Adults age 65+ who are not in the labor force and not students.

  5. Non-working adult: Adults not employed, not students, and not retired (includes stay-at-home adults, those on leave or furlough, and unemployed).

  6. Part-time worker: Adults employed part-time or as unpaid volunteers/interns.

  7. Full-time worker: Adults employed full-time or self-employed.

  8. 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)
} # }