# csdata

`csdata` provides structural reference data for Norway: location hierarchies, population counts, and the conventions used across the csverse format.

See https://niphr.github.io/csdata/reference/index.html for an overview of all available datasets and functions.

## Location

Valid locations and location types are available in `csdata::nor_locations_names()`. Entries with uncommon or internal use are shown with a strikethrough.

Valid locations and location types in the csverse format
Geo (Granularity) | N | Examples
--- | --- | ---
location_code1 | location_name2 | location_name_description_nb3 | location_name_file_nb_utf4 | location_name_file_nb_ascii5
nation | 1 | nation_nor | Norge-Noreg-Norway | Norge-Noreg-Norway | Norge_Noreg_Norway | norge_noreg_norway
georegion6 | 5 | georegion_nor1 | Nord-Norge-Davvi-Norggas | Nord-Norge-Davvi-Norggas (landsdel) | Nord_Norge_Davvi_Norggas_landsdel | nord_norge_davvi_norggas_landsdel
county | 15 | county_nor42 | Agder | Agder (fylke) | Agder_fylke | agder_fylke
notmainlandcounty | 2 | notmainlandcounty_nor22 | Utenfor fastlands-Norge (Jan Mayen) | Utenfor fastlands-Norge (Jan Mayen) (fylke) | Utenfor_fastlands_Norge_Jan_Mayen_fylke | utenfor_fastlands_norge_jan_mayen_fylke
missingcounty | 1 | missingcounty_nor99 | Ukjent fylke | Ukjent fylke (fylke) | Ukjent_fylke | ukjent_fylke
municip | 357 | municip_nor1820 | Alstahaug | Alstahaug (kommune i Nordland-Nordlándda) | Alstahaug_kommune_i_Nordland_Nordlándda | alstahaug_kommune_i_nordland_nordlandda
notmainlandmunicip | 2 | notmainlandmunicip_nor2200 | Jan Mayen | Jan Mayen (kommune i Utenfor fastlands-Norge (Jan Mayen)) | Jan_Mayen_kommune_i_Utenfor_fastlands_Norge_Jan_Mayen | jan_mayen_kommune_i_utenfor_fastlands_norge_jan_mayen
missingmunicip | 1 | missingmunicip_nor9999 | Ukjent kommune | Ukjent kommune (kommune i Ukjent fylke) | Ukjent_kommune_i_Ukjent_fylke | ukjent_kommune_i_ukjent_fylke
wardoslo | 15 | wardoslo_nor030112 | Alna | Alna (bydel i Oslo-Oslove) | Alna_bydel_i_Oslo_Oslove | alna_bydel_i_oslo_oslove
wardbergen | 8 | wardbergen_nor460101 | Arna | Arna (bydel i Bergen) | Arna_bydel_i_Bergen | arna_bydel_i_bergen
wardstavanger | 9 | wardstavanger_nor110303 | Eiganes og Våland | Eiganes og Våland (bydel i Stavanger) | Eiganes_og_Våland_bydel_i_Stavanger | eiganes_og_valand_bydel_i_stavanger
wardtrondheim | 4 | wardtrondheim_nor500104 | Heimdal | Heimdal (bydel i Trondheim) | Heimdal_bydel_i_Trondheim | heimdal_bydel_i_trondheim
extrawardoslo | 2 | extrawardoslo_nor030117 | Marka | Marka (bydel i Oslo-Oslove) | Marka_bydel_i_Oslo_Oslove | marka_bydel_i_oslo_oslove
missingwardbergen | 1 | missingwardbergen_nor460199 | Ukjent bydel i Bergen | Ukjent bydel i Bergen (bydel i Bergen) | Ukjent_bydel_i_Bergen | ukjent_bydel_i_bergen
missingwardoslo | 1 | missingwardoslo_nor030199 | Ukjent bydel i Oslo | Ukjent bydel i Oslo (bydel i Oslo-Oslove) | Ukjent_bydel_i_Oslo_Oslove | ukjent_bydel_i_oslo_oslove
missingwardstavanger | 1 | missingwardstavanger_nor110399 | Ukjent bydel i Stavanger | Ukjent bydel i Stavanger (bydel i Stavanger) | Ukjent_bydel_i_Stavanger | ukjent_bydel_i_stavanger
missingwardtrondheim | 1 | missingwardtrondheim_nor500199 | Ukjent bydel i Trondheim | Ukjent bydel i Trondheim (bydel i Trondheim) | Ukjent_bydel_i_Trondheim | ukjent_bydel_i_trondheim
baregion7 | 159 | baregion_nor111 | Alstahaug | Alstahaug (BA-region) | Alstahaug_BA_region | alstahaug_ba_region
mtregion8 | 5 | mtregion_nor4 | Midt-Norge | Midt-Norge (Mattilsynet-region) | Midt_Norge_Mattilsynet_region | midt_norge_mattilsynet_region
lab | 26 | lab_nor000030 | Akershus Universitetssykehus | Akershus Universitetssykehus (lab) | Akershus_Universitetssykehus_lab | akershus_universitetssykehus_lab
1 location_code: Used a) inside datasets and b) in data file names for transfer of data/results between analytic systems. All values are unique.
2 location_name: Used (rarely) inside results (figures, tables, documents). Can be confusing as some names are duplicated. Its rare usage is demarcated by a line through the text.
3 location_name_description_nb: Used (frequently) inside results (figures, tables, documents). All values are unique.
4 location_name_file_nb_utf: Used (frequently) in the file names for results (figures, tables, documents). All values are unique.
5 location_name_file_nb_ascii: Used (rarely) in the file names for results (figures, tables, documents). Used if file systems have problems with the Norwegian letters æøå. All values are unique.
6 Landsdeler/riskdeler. Geographical regions.
7 Bo- og arbeidsmarkedsregioner. Housing and labor market regions.
8 Mattilsynet-regioner. Food authority regions.

## Ages

Ages must be coded as characters and must always contain three digits. For age ranges, join the two ages with an underscore (e.g. `005_010`).

Use `085p` rather than `>=085` or `85+`; this keeps conversion from long to wide format straightforward.

Valid ages in the csverse format
Value | class | Definition
--- | --- | ---
"000" | character | One year age group (0 year olds)
"079" | character | One year age group(79 year olds)
"000_004" | character | Age span of 0-4 year olds
"065p" | character | Age span of >=65 year olds
"missing" | character | Missing/unknown
"total" | character | Everyone

This format keeps data sorted correctly and produces valid variable names when pivoted to wide format.

Missing ages should be coded as `"missing"`.

## Sex

Sex must be coded as a character.

Valid sexes in the csverse format
Value | class | Definition
--- | --- | ---
"male" | character | Male
"female" | character | Female
"missing" | character | Missing/unknown
"total" | character | Everyone

Missing sex should be coded as `"missing"`.