Overview
tidylfs
is designed to easily add more variables: * Find the relevant variables in the ONS LFS User guidance. * Add them to user_extra_mappings
. * 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 which is handled gracefully.
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)