*! version 1.0.0 14okt2024

Title

gencpr -- For users of Danish CPR numbers.

Syntax

gencpr
newvar
[if] [in]
, from(varname) [options]

Main
* from(varname) takes odd patterns of CPR numbers storred in varname and generates newvar with the pattern ddmmyy-####

modulus generate variable mod11 with the Modulus-11 test

gender generate binary gender variable koen

birthday generate variable birthday

ageat(varname) generate variable age at the date in varname

agefracat(varname) generate variable age_frac, age incl. its fractional part, at the date in varname

gt100 use the 7th digit in newvar to determine the birth century

* from(varname) is required.

Description

gencpr takes most odd patterns of CPR numbers storred in from(varname) and generates a newvar containing CPR numbers with the standard pattern ddmmyy-####.
gencpr is therefore useful for cleaning your current CPR variabel if it contains many different patterns of CPR numbers.
Options performs a Modulus-11 test on the new CPR and generates gender, birthday and age.

Options

Main

from(varname)} is required. varname must be a string variable but it may contain mamy different patterns of CPR (e.g. ddmmyyyy-1234, dmmyy-xyz4, d.mm-yy, dd/mmyyyy).

modulus generates a variable mod11,
with the results of a Modulus-11 test of CPR validity.
In mod11, 0 indicates an invalid CPR number and 1 indicated a valid CPR number.
The Modulus 11 test will sometimes provide a wrong answer; for example, some CPR patterns (e.g. 000000-0000) will turn out as valid, and after 2007, some CPR munbers are Modulus-11 invalid
(see https://da.wikipedia.org/w/index.php?title=Modulus_11&oldid=11133611).
So you should only use the Modulus-11 test as a guideline for CPR validity.

gender generates a binary gender variable koen from the last digit in newvar. The last digit of the CPR is odd for males and even for females, and koen is 0 for females and 1 for males.
If the last digit is not 0-9, koen is missing.

birthday generates an e_d variable birthday form the first 6 numbers in newvar.
If for example the CPR is 010160-1234, then birthday is 01jan1960.
See birthday(); by default, s_nl="01mar" and Y is the current system year (see cretur).
So the birthday is correct for people who are less than 100 years old.

ageat(varname) generates the age in years at the e_d date in varname.
See age(); by default, s_nl="01mar" and Y is the current system year (see cretur). So the age is correct for people who are less than 100 years old.

agefracat(varname) generates the variable age_frac, the age in years, including its fractional part, at the e_d date in varname.
See age_frac(); by default, s_nl="01mar" and Y is the current system year (see cretur). So the age_frac is correct for people who are less than 100 years old.

gt100 uses the 7th digit in the newvar to determine the birth century, so you should make sure that the 7th digits in newvar is correct when you use this option.
If all people in your sample are less than 100 years old it is better to use the default setting. gt100 will only influence variables birthday, age and age_frac.

Remarks

For detailed information on the Danish CPR, see
https://da.wikipedia.org/w/index.php?title=CPR-nummer&oldid=11492353.

Examples

. gencpr newcpr, from(oldcpr)

. gencpr cleancpr, from(oddcpr) modulus gender birthday ageat(surveydate) agefracat(surveydate)

. gencpr newcpr, from(oldcpr) birthday ageat(died) agefracat(died) gt100

Author

Christoffer Scavenius

VIVE – The Danish Centre for Social Science Research

E-mail: css@vive.dk