Skip to contents

Overview

  • tidylfs is designed to be easily extended. Adding variables and summaries is a few steps:
    • Find the relevant variables in the ONS LFS User guidance.
    • Add them to the function below.
    • Load the function, and pass it as an argument to lfs_compile.
  • For example, to add marital status:
user_extra_mappings <- function(lfs_file_column_names) {

  custom_variables <- tibble::tribble(
    ~lfs_name,       ~new_name,     ~type,
    "MARSEX6", "SEX_AND_MARITAL_STATUS", "factor"
    )

  return(custom_variables)
}

lfs_compile("your_lfs_rds_directory", extra_mappings = user_extra_mappings)
  • To add a variable that changes over time, use pick_var. As an example, degree class is DEGCLS7 from 2007 onwards, and DEGCLS before then. This code imports those as a factor (retaining the SPSS labels), and calls the new column DEGREE_CLASS.
user_extra_mappings <- function(lfs_file_column_names) {

  # This will pick DEGCLS7 if it exists in the quarterly file,
  # if not then DEGCLS, otherwise it'll return NA.
  degree_class <- pick_var(c("DEGCLS7", "DEGCLS"), lfs_file_column_names)

  custom_variables <- tibble::tribble(
    ~lfs_name,       ~new_name,     ~type,
    "MARSEX6", "SEX_AND_MARITAL_STATUS", "factor",
    degree_class, "DEGREE_CLASS", "factor"
    )

  return(custom_variables)
}

lfs_compile("your_lfs_rds_directory", extra_mappings = user_extra_mappings)