demprep: demprep: Prepare demographic data

Description Calculate ages, periods, and cohorts from dates Cleaning existing labels Making labels complete and consistent Other tasks Example workflows

Description

Prepare demographic data for subsequent analysis, focusing particularly on the specification of age groups, periods, and cohorts.

Calculate ages, periods, and cohorts from dates

The following functions calculate ages, cohorts, and periods from dates.

age period cohort
date_to_age_year date_to_period_year date_to_cohort_year
date_to_age_quarter date_to_period_quarter date_to_cohort_quarter
date_to_age_month date_to_period_month date_to_cohort_month

demprep also has functions for calculating Lexis triangles from dates. See vignette("demprep") for a definition of Lexis triangles.

Cleaning existing labels

clean_age, clean_period, and clean_cohort convert existing age, period, and cohort labels to a standard design.

clean_age_df, clean_period_df clean_cohort_df, is_valid_age, is_valid_period, and is_valid_cohort can be used to control and check the cleaning-up process.

Making labels complete and consistent

Labels can be consolidated, and gaps filled in, using the format functions:

age period cohort
format_age_year format_period_year format_cohort_year
format_age_multi format_period_multi format_cohort_multi
format_age_custom format_period_custom format_cohort_custom
format_age_quarter format_period_quarter format_cohort_quarter
format_age_month format_period_month format_cohort_month
format_age_lifetab
format_age_births

Other tasks

impute_date and impute_dob randomly generate in missing dates.

as_date_range_year, as_date_range_multi, as_date_range_custom, as_date_range_quarter, and as_date_range_month create non-standard but unambiguous period and cohort labels.

flip_to_start and flip_to_end help with reformatting one-year period and cohort labels.

Example workflows

Create 5-year age groups and 1-year periods from data with dates

Create 5-year age groups, periods, and cohorts from data with existing age, period, and cohort labels.


johnrbryant/demprep documentation built on Dec. 31, 2021, 11:58 a.m.