format_cohort_quarter: Create consistent, complete quarter (three-month) cohorts

Description Usage Arguments Details Value See Also Examples

View source: R/format_cohort.R

Description

Given a vector of cohort labels, create a factor where the levels contain a complete set of cohorts. If open_first is TRUE, then the earliest cohort has no lower limit.

Usage

1
format_cohort_quarter(x, break_min = NULL, open_first = NULL)

Arguments

x

A vector of cohort labels.

break_min

An integer or NULL (the default). If an integer, it is the year in which the oldest cohort begins.

open_first

Whether the oldest cohort has no lower limit.

Details

open_first defaults to TRUE if a value for break_min is supplied, or if any intervals in x is open, and to FALSE otherwise.

Quarters are defined as follows:

Quarter Start End
Q1 1 January 31 March
Q2 1 April 30 June
Q3 1 July 30 September
Q4 1 October 31 December

If x contains NA, then the levels of the factor created by format_cohort_quarter also contain NA.

Value

A factor with the same length as x.

See Also

Other functions for reformating cohort labels are

date_to_cohort_year calculates cohorts from dates.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
format_cohort_quarter(x = c("2000 Q4", "2005 Q1", NA, "2004 Q3"))

## 'open_first' defaults to TRUE, since 'x'
## contains an open interval
format_cohort_quarter(x = c("<2000 Q4", "2005 Q1", NA, "2004 Q3"))

## 'open_first' defaults to TRUE, since
## a value for 'break_min' is supplied
format_cohort_quarter(x = c("2000 Q4", "2005 Q1", NA, "2004 Q3"),
                      break_min = "2004 Q1")

## 'break_min' specified, and 'open_first' set to FALSE
format_cohort_quarter(x = c("2005 Q1", NA, "2004 Q3"),
                      break_min = "2004 Q1",
                      open_first = FALSE)

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