```-------------------------------------------------------------------------------
help for pnrcheck
-------------------------------------------------------------------------------

pnrcheck

pnrcheck variable_pnr [, savepnr(variable_name) saveind(variable_name)
listwrong listmissing display ]

Description

pnrcheck Algorithm to verify the check digit in Swedish personal
identification numbers (PNRs).  The check digit is the tenth digit
constructed from the preceding nine digits, according to date of
birth and gender.

Remark

The variable_pnr could be either a string (A) or a numeric variable (B).
The check digit could also be missing (C). See help datatypes.

(A) The variable_pnr could be stored as string

Case 1 "4102179704" str10 (standard storage type)
Case 2 "194102179704" str12 (if there are 2 initial numbers of the year)
Case 3 "410217-9704" str11 (if there is a minus sign)
Case 4 "19410217-9704" str13 (if there is a minus sign and the 2 initial
numbers of the year)

(B) The variable_pnr could be stored as number with double precision

Case 5 4.102e+09 double (corresponding to Case 1)
Case 6 1.914e+11 double (corresponding to Case 2)

(C) The tenth digit or check digit of the variable_pnr could be missing

Case 7 4.102e+08 double (Case 5 without the check digit)
Case 8 "410217970" str9 (Case 1 without the check digit)

Algorithm

STEP 1 Multiply each of the first nine digits in the PNR by the digits
2,1,2,1,2,1,2,1,2

STEP 2 Calculate the cumulative sum of each of these 9 calculations

STEP 3 Verify if the check digit of variable_pnr is equal to the number
we would have to add to the cumulative sum (from STEP 2) to obtain a
multiple of 10

Options

savepnr(variable_name) saves the right PNR variable

saveind(variable_name) saves an indicator variable according to the check
digit status (0=Right, 1=Wrong, 2=Missing)

display displays algorithm's results: number of wrong and right PNR,
percentage

listwrong lists temporary variables input_pnr i_check output_pnr o_check
only for individuals whose check digit is wrong

listmissing lists temporary variables input_pnr i_check output_pnr
o_check only for individuals whose check digit is missing

Examples

. insheet using
http://nicolaorsini.altervista.org/stata/tutorial/p/ex_pnrs.txt,
clear
. pnrcheck pnr
. pnrcheck pnr, savep(pnrright) di
. pnrcheck pnr, savep(pnrright) savei(indvar) di listw

Authors

Nicola Orsini, I.M.M., Karolinska Institutet, Sweden
Nicholas J. Cox, University of Durham, U.K.
Rino Bellocco, M.E.B., Karolinska Institutet, Sweden

Support

Nicola Orsini, http://nicolaorsini.altervista.org, Karolinska Institutet,
Sweden
nicola.orsini@imm.ki.se

Also see

[R] destring
[U] Commands for dealing with strings

On-line:  help for destring, macro, strfun

```