Package 'csdata'

Title: Structural Data for Norway
Description: Datasets relating to population in municipalities, municipality/county matching, and how different municipalities have merged/redistricted over time from 2006 to 2024.
Authors: Richard Aubrey White [aut, cre] , Chi Zhang [aut] , CSIDS [cph]
Maintainer: Richard Aubrey White <[email protected]>
License: MIT + file LICENSE
Version: 2024.4.26
Built: 2025-01-24 05:13:51 UTC
Source: https://github.com/csids/csdata

Help Index


Adds granularity_geo to a given data set

Description

Adds granularity_geo to a given data set

Usage

add_granularity_geo_to_data_set(x, location_reference = NULL)

Arguments

x

A data.table containing a column called "location_code".

location_reference

A location reference data.table.

Value

A data.table containing an extra column called "granularity_geo".

Examples

library(data.table)
data <- data.table(location_code = c("norge", "county03", "blah"))
csdata::add_granularity_geo_to_data_set(data)
print(data)

library(data.table)
data <- data.table(location_code = c("norge", "county03", "blah"))
csdata::add_granularity_geo_to_data_set(data, location_reference = csdata::nor_locations_names())
print(data)

Adds iso3 to a given data set

Description

Adds iso3 to a given data set

Usage

add_iso3_to_data_set(x)

Arguments

x

A data.table containing a column called "location_code".

Value

A data.table containing an extra column called "iso3".

Examples

library(data.table)
data <- data.table(location_code = c("norge", "county03", "blah"))
csdata::add_iso3_to_data_set(data)
print(data)

An environment containing configuration variables

Description

Available configuration variables:

  • border_nor (default 2024): The year in which Norwegian geographical boundaries were designated. Valid values: 2020, 2024.

Usage

config

Format

An object of class environment of length 1.

Examples

print(ls(csdata::config))
for(i in names(csdata::config)){
  cat(i, ":", csdata::config[[i]], "\n")
}

Convert location_code to granularity_geo

Description

Convert location_code to granularity_geo

Usage

location_code_to_granularity_geo(x, location_reference = NULL)

Arguments

x

Either a vector, or a data.frame/data.table containing a column called "location_code".

location_reference

A location reference data.table.

Value

Character vector the same length as x, containing the corresponding granularity_geo.

Examples

csdata::location_code_to_granularity_geo(c("nation_nor", "county_nor03"))

Convert location_code to iso3

Description

Convert location_code to iso3

Usage

location_code_to_iso3(x)

Arguments

x

Either a vector, or a data.frame/data.table containing a column called "location_code".

Value

Character vector the same length as x, containing the corresponding iso3.

Examples

csdata::location_code_to_iso3(c("nation_nor", "county_nor03"))

Norwegian characters in unicode

Description

Norwegian characters in unicode

Usage

nb

Format

An object of class list of length 6.

Examples

print(csdata::nb)

Location hierarchies in Norway

Description

Calculates the relationship between different locations in Norway, according to geographic granularity. For example, which municipalities are inside which counties.

Usage

nor_locations_hierarchy_from_to(
  from,
  to,
  include_to_name = FALSE,
  border = csdata::config$border_nor
)

Arguments

from

wardoslo, wardbergen, wardtrondheim, wardstavanger, municip, baregion, county, georegion, mtregion, notmainlandmunicip, notmainlandcounty, missingmunicip, missingcounty

to

wardoslo, wardbergen, wardtrondheim, wardstavanger, municip, baregion, county, georegion, mtregion, notmainlandmunicip, notmainlandcounty, missingmunicip, missingcounty

include_to_name

Do you want to include the name of the 'to' location?

border

The year in which Norwegian geographical boundaries were designated (2020, 2024).

Value

Data.table containing the columns:

  • from_code

  • to_code

  • to_name (if include_to_name==TRUE)

Examples

csdata::nor_locations_hierarchy_from_to(from="wardoslo", to="county")
csdata::nor_locations_hierarchy_from_to(from="municip", to="baregion")

All names in Norway

Description

All names in Norway

Usage

nor_locations_names(border = csdata::config$border_nor)

Arguments

border

The year in which Norwegian geographical boundaries were designated (2020, 2024).

Value

location_code

Location code.

location_name

Location name.

location_name_short

3 letter location name for nation and county. A shorter location name for wardoslo and extrawardoslo.

location_name_description_nb

Location name with additional description.

location_name_file_nb_utf

Location name that should be used in file names, with Norwegian characters.

location_name_file_nb_ascii

Location name that should be used in file names, without Norwegian characters.

location_order

The preferred presentation order.

granularity_geo

nation, county, municip, wardoslo, wardbergen, wardstavanger, wardtrondheim, baregion, lab.

Source

https://no.wikipedia.org/wiki/Liste_over_norske_kommunenummer

Examples

nor_locations_names()

All redistricting in Norway

Description

This function returns a dataset that is used to transfer "original" datasets to the 2020 or 2024 borders.

Usage

nor_locations_redistricting(border = csdata::config$border_nor)

Arguments

border

The year in which Norwegian geographical boundaries were designated (2020, 2024).

Value

location_code_current

The location code per today.

location_code_original

The location code as of "calyear".

calyear

The year corresponding to "county_code_original".

weighting

The weighting that needs to be applied.

granularity_geo

nation, county, municip, wardbergen, wardoslo, wardstavanger, wardtrondheim, missingwardbergen, missingwardoslo, missingwardstavanger, missingwardtrondheim, notmainlandcounty, notmainlandmunicip, missingcounty

Examples

csdata::nor_locations_redistricting()

Population in Norway by categories

Description

A function that easily categorizes the Norwegian population into different age categories.

Usage

nor_population_by_age_cats(
  cats = NULL,
  include_total = TRUE,
  include_9999 = FALSE,
  border = csdata::config$border_nor
)

Arguments

cats

A list containing vectors that you want to categorize.

include_total

Boolean. Should 'total' be included as an age cat?

include_9999

Boolean. Should the current year is duplicated and added as "calyear==9999". This is in accordance with the cstidy principles regarding granularity_time=="event_*".

border

The year in which Norwegian geographical boundaries were designated (2020, 2024).

Value

A data.table containing the following columns:

  • granularity_geo

  • location_code

  • age (as specified in the argument "cats")

  • sex ("total")

  • calyear

  • pop_jan1_n

  • imputed

Examples

## Not run: 
nor_population_by_age_cats(cats = list(c(1:10), c(11:20)))

## End(Not run)

Swedish characters in unicode

Description

Swedish characters in unicode

Usage

se

Format

An object of class list of length 4.

Examples

print(csdata::se)

Set options in the package config

Description

Set options in the package config

Usage

set_config(border_nor = NULL)

Arguments

border_nor

The year in which Norwegian geographical boundaries were designated. Valid values: 2020, 2024.

Value

Nothing. Side effect of setting the config environment.