format_age_births: Create consistent, complete age groups for tabulating births

Description Usage Arguments Details Value See Also Examples

View source: R/format_age.R

Description

Given a vector of age group labels, create a factor that contains levels for all ages between the minimum and maximum ages for reproduction.

Usage

1
2
3
4
5
6
7
8
format_age_births(
  x,
  break_min = 15,
  break_max = 50,
  width = 5,
  recode_up = FALSE,
  recode_down = FALSE
)

Arguments

x

A vector of age group labels. The age of the parent at the time of the birth of the child.

break_min

An integer or NULL. Defaults to 15.

break_max

An integer or NULL. Defaults to 50.

width

The width in years of the age groups to be created. A positive integer defaulting to 5.

recode_up

If TRUE, births to parents aged less than break_min are treated as occurring to people in the lowest repoductive age group.

recode_down

If TRUE, births to parents aged break_max or more are treated as occurring to people in the highest reproductive age group.

Details

The minimum and maximum ages for reproduction are specified via arguments break_min and break_max. If, for instance, break_min is 15 and break_max is 50, then all births are assumed to occur to women aged 15 to 49 (inclusive).

If break_min or break_max is set to NULL, rather than to a specific value, then format_age_births finds the narrowest range that accommodates the values in x.

Datasets sometimes contain a few births to parents younger than the assumed minimum age of reproduction, or births to parents older than the assumed maximum age of reproduction. Demographers often recode ages outside the expected range so that they fall just within the expected range. This recoding can be justified on the grounds that some of the original ages may have been misreported, but it also alleviates any problems with tabulations having small counts at extreme ages. Recoding of parents' ages outside the expected range is controlled by parameters recode_up and recode_down. The default is for no recoding to occur.

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

Value

A factor with the same length as x.

See Also

Other functions for creating age groups are

date_to_age_year calculates ages from dates.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
format_age_births(x = c(22, 34, 19))

format_age_births(x = c("20-24", "37", NA, "32", "21-24"))

format_age_births(x = c("20-24", "37", "32", "21-24"),
                  width = 10,
                  break_min = 20)

format_age_births(x = c(20, 37, 15),
                  width = 1,
                  break_max = 45)

## allow youngest and oldest age groups to be
## determined by the data
format_age_births(x = c("21", "33", "22-24"),
                  break_min = NULL,
                  break_max = NULL)

## recode ages outside the expected range
format_age_births(x = c("22", "13-14", "55", "10-19"),
                  recode_up = TRUE,
                  recode_down = TRUE)

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