recode_age

recode_age(x, breaks=None, labels=None, quiet=False)

Recode age into standard survey bands.

Convenience wrapper over bin_numeric() using the standard survey age bands. Ages are first passed through ensure_numeric(), so messy entries like “22 years” or “age: 31” are handled, then binned using left-closed bands. An answer with no number in it at all (“young”, “prefer not to say”) becomes missing and is counted in a message, so a column that was never numeric does not pass for a column of missing ages. The default bands come from the age_breaks / age_labels options. For generational cohorts use recode_generation() instead.

Parameters

Name Type Description Default
x list or Series Ages, as numbers or text. required
breaks list Override the default bands; None (default) uses the age_breaks / age_labels options. None
labels list Override the default bands; None (default) uses the age_breaks / age_labels options. None
quiet bool If False (default), report answers that held no number and answers that fell outside the bands. Set True to silence both. False

Returns

Name Type Description
pandas.Series A categorical of age-band labels, categories in band order.

See Also

bin_numeric, recode_generation, ezrsurvey_options

Examples

>>> recode_age(["17", "22 years", "31", "47"])