# Gender Code

Key: `identity.person.gender_code`

Single-character sex/gender code. ICAO Doc 9303 passport sex field uses M (male), F (female), X (unspecified); the machine readable zone writes an unspecified sex as the filler character \< (part 4). ISO/IEC 5218 numeric coding uses 0 (not known), 1 (male), 2 (female), 9 (not applicable). Matched case-insensitively (ac-02).

Page: <https://meridian.online/docs/finetype/types/identity/person/gender_code>

Samples: `M`, `F`, `X`, `1`

## Use it

Shell

```shell
finetype infer -i 'M' --mode column
# → identity.person.gender_code
```

DuckDB

```sql
SELECT ft_infer('M');
-- → 'identity.person.gender_code'
```

Cast template: {col} is your column

```sql
CAST(UPPER({col}) AS VARCHAR)
```

## Background

### Origin

ISO/IEC 5218, Information technology — Codes for the representation of human sexes, is an international standard that represents human sexes with a language-neutral single-digit code.[[1]](https://en.wikipedia.org/wiki/ISO/IEC_5218) Its four codes are 0 for not known, 1 for male, 2 for female and 9 for not applicable.[[1]](https://en.wikipedia.org/wiki/ISO/IEC_5218) The standard was proposed in November 1976 and updated in June 2022.[[1]](https://en.wikipedia.org/wiki/ISO/IEC_5218) It is maintained by the ISO/IEC JTC 1 subcommittee on data management and interchange, ISO/IEC JTC 1/SC 32.[[1]](https://en.wikipedia.org/wiki/ISO/IEC_5218) The standard states that no significance is to be placed on male being coded 1 and female 2, which merely reflects existing practice in the countries that initiated it.[[1]](https://en.wikipedia.org/wiki/ISO/IEC_5218) Since its 2022 revision, the standard states that its scope does not cover human gender identities.[[1]](https://en.wikipedia.org/wiki/ISO/IEC_5218)

### Use

The TEI Guidelines for encoding texts define a data.sex datatype whose values are 0, 1, 2 and 9.[[2]](https://tei-c.org/Vault/P5/1.6.0/doc/tei-p5-doc/en/html/ref-data.sex.html) TEI states that those values are taken from ISO 5218:2004.[[2]](https://tei-c.org/Vault/P5/1.6.0/doc/tei-p5-doc/en/html/ref-data.sex.html)

Keep 0 and 9 apart when you clean the column: not known and not applicable answer different questions, and folding both into a null loses that. (Meridian's view)

### Where you'll meet it

Insee's Fichier des personnes décédées, published on data.gouv.fr, stores sex as a one-character numeric field at position 81 of each record.[[3]](https://www.data.gouv.fr/datasets/fichier-des-personnes-decedees) In that file, 1 means male and 2 means female.[[3]](https://www.data.gouv.fr/datasets/fichier-des-personnes-decedees)

## Sources

1. [ISO/IEC 5218 - Wikipedia](https://en.wikipedia.org/wiki/ISO/IEC_5218) — secondary source
2. [TEI macro data.sex](https://tei-c.org/Vault/P5/1.6.0/doc/tei-p5-doc/en/html/ref-data.sex.html) — documentation
3. [Fichier des personnes décédées](https://www.data.gouv.fr/datasets/fichier-des-personnes-decedees) — dataset

## How it's detected

Sourced to ICAO Doc 9303 (alpha M/F/X) and ISO/IEC 5218 (numeric 0/1/2/9). The prior ^\[MFX\]$ pattern was uppercase-only and its description wrongly listed \`O\` as valid — ICAO uses X (not O) for unspecified. Converted to an enum so case-insensitive matching flows from ac-02; the transform still uppercases for materialisation. The filler \`\<\` is the ICAO Doc 9303 part 4 MRZ convention for an unspecified sex. It is a one-character punctuation mark, so no guard promotes a column to this type on it (the value-based gender rule reads only M/F/X; the type is neither a ceded leaf nor on the fast path) and a detector holds discrimination to the earlier codes: a column made only of \`\<\` conforms but is demoted, as before, while a zone column with a few fillers among M/F keeps its type.
