-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
180 lines (107 loc) · 8.71 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
---
title: "Kommuneendringer"
output: github_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
I often find myself working with data that deals with Norwegian municipalities (kommuner) and counties (fylker), either in individual level data (a persons residence, for example) or on data on the municipal level itself. The standard way of working with municipalities is to use the municipality number, which is a four digit number, where the two first digits indicate the county number. In the recent years (2018 - 2024) there has been large reforms of the municipal and county structure, causing a lot of frustration when working with municipal data, especially if the data spans several years. I often find myself just wanting to translate the code for a municipality from one point in time to another point in time, while taking into account mergers, splits, name changes, county changes etc. The goal of the `kommuneendringer` R package is to do just that.
This package is *opinionated*, in the sense that it works in ways that suits my needs, which might be contrary to official guidelines for how to deal with changes in the municipality structure. Please take a good look at the examples and explanations below to get an understanding of how it works.
## Installation
```{r eval=FALSE}
install.packages("devtools")
devtools::install_github("opisthokonta/kommuneendringer")
```
## Features and limitatons
The main functionality of this package is the `translate_knr` function. This can translate the four-digit municipal code between different time point starting from January 1st 1977. It is updated with all changes up until January 1st 2024.
It currently only supports translating municipality codes. I will soon add functionality for translating county codes as well.
Special municipal codes such as those for Svalbard, off-shore installations , etc, are not supported.
In 2024 some mergers between counties and municipalities from 2020 were reversed. I hope to add support for taking this into account in the future.
## Examples
First load the package:
```{r}
library(kommuneendringer)
```
### Example 1: Changing county
A simple example is the municipality Halden. It hasn't merged with any other municipality recently, but changed county, and therefore its code, in 2020 (from Østfold to Viken). The code was changed again in 2024, when Viken was split and the county of Østfold was re-established. The new Østfold county got a new county number and Halden's new code was therefore not the same as before 2020.
```{r}
# Change code from 0101 to 3001 on January 1st 2020.
translate_knr('0101', from_date = '2019-01-01', to_date = '2020-05-17')
```
Lets see what it changed to in 2024:
```{r}
translate_knr('3001', from_date = '2020-01-01', to_date = '2024-05-17')
```
It is also possible to make longer jumps, say if you have some Halden data from 2008, and want to merge it with data from 2024:
```{r}
translate_knr('0101', from_date = '2008-01-01', to_date = '2024-05-17')
```
It is also possible to go backwards in time:
```{r}
translate_knr('3101', from_date = '2024-01-01', to_date = '2015-05-17')
```
### Example 2: Merged municipalities
An example of municipalities that merged are Søgne, Songdalen and Kristiansand, which merged in 2020. When municipalities merge, the `translate_knr` function will, if possible, give you the code for the merged municipality. You can then perhaps aggregate data from the historical municipalities as if they are the new municipality.
```{r}
# Søgne's code was 1018.
translate_knr('1018', from_date = '2018-01-01', to_date = '2023-05-17')
```
```{r}
# Songdalen's code was 1017
translate_knr('1017', from_date = '2018-01-01', to_date = '2023-05-17')
```
```{r}
# Kristiansand's code was 1001
translate_knr('1001', from_date = '2018-01-01', to_date = '2023-05-17')
```
Let's take a look what happens if you try to translate the code backwards in time:
```{r}
translate_knr('4204', from_date = '2023-01-01', to_date = '2015-05-17')
```
The function will return NA and a warning, since there is no unique predecessor municipality. The municipality with code 4204 in 2023 can correspond to any of the three predecessors (1001, 1017 and 1018) in 2015, and without any other information, we can not know which one is the correct one.
### Example 3: Split municipality
Tysfjord municipality (code 1850) was in 2020 split in two, and the two parts merged with other municipalities. There is no unique successor municipality and it is therefore not possible to translate the code from before to after January 1st 2020.
```{r}
translate_knr('1850', from_date = '2019-01-01', to_date = '2020-05-17')
```
## How it works
Data from SSB. The graph model.
New node when:
* Code change
* Name change (including when the municipality get official sami and kven names)
* Merger, even when the new municipality keep name and code from predecessors.
## Regarding changes in the municipal codes
So dealing with changes in the municipal codes are frustrating for a number of reasons. Typically, a municipality change code
* When municipalities or counties are merged. The merged municipality will usually get a new code, even if it keeps the name of one of its predecessors. But there are exceptions to this rule, which is documented below.
* When municipalities or counties split. The new municipalities or counties will each get a new code.
* When municipalities change county. Since the first two digits of the municipal code indicate the county, the code will change correspondingly. This also happens when counties merge or split.
The code will not change
* When the municipality changes name. This includes when a municipality get an additional official name in one of the minority langues (sami or kven).
Code and name changes always takes place on January 1st.
### Exceptional cases
This section is mostly a note to myself, to keep track of those instances that need particular attention to get right.
Usually when municipalities are merged, they get a new code, but this has not always happened:
* When 0716 Våle and 0718 Ramnes were merged to become Re in 2002, the new municipality kept Våle's code 0716.
* When 1804 Bodø and 1842 Skjerstad were merged in 2005, the kept the name and code for 1804 Bodø.
* When 1141 Finnøy and 1142 Rennesøy were merged with 1103 Stavanger in 2020, the new municipality kept the name and code for 1103 Stavanger.
* When 5030 Klæbu was merged with 5001 Trondheim in 2020, the new municipality kept the name and code for 5001 Trondheim.
#### Municipalities that split
Usually, when there are changes in the municipal structure, it is because two or more municipalities merge, but there are exceptions to this, when sometimes municipalities split:
* In 2020, the municipality 1850 Tysfjord was split in two. One part merged with 1805 Narvik to become 1806 Narvik, and the other part merged with 1849 Hammarøy to become 1875 Hammarøy.
* In 2020, the municipality 5012 Snillfjord was split in 3. One part was merged with 3 other muncipalities to become 5059 Orkland. The second part was merged with two other municipalities to become 5055 Heim. The third part was merged with 5013 Hitra to become 5056 Hitra.
* In 2020, the municipalities 1504 Ålesund and 1534 Haram merged to become 1507 Ålesund. In 2024 they reversed the merger, and split into 1508 Ålesund and 1580 Haram.
#### Municipalities that share names
There are some municipalities that share the same name. Conventionally the name of the county is added in parenthesis to distinguish them.
* Våler (Innlandet, before 2020: Hedmark), and Våler (Østfold, in 2020-2023: Viken).
* Herøy (Møre og Romsdal) and Herøy (Nordland).
* Nes (Akershus) Nes (Buskerud). Nes in Buskerud changed name to Nesbyen in 2020 since both municipalities then ended up in the same county (Viken) when Akershus, Buskerud and Østfold merged in 2020. After Viken split in 2024, Nesbyen kept its new name.
* Os (Hedmark) and Os (Hordaland). Os in Hordaland was merged with another municipality in 2020 and got a new name.
* Bø (Nordland), Bø (Telemark). Bø in Telemark merged with another municipality in 2020 and got a new name.
* Sande (Vestfold) and Sande (Møre og Romsdal). Sande in Vestfold merged with another municipality in 2020 and got a new name.
Samisnke navn på karasjon og nesseby, dato..
## Links
The data is sourced from Statistics Norway (Statistisk Sentralbyrå, SSB). Here are some relevant links.
* [Alle endringer i de regionale inndelingene](https://www.ssb.no/metadata/alle-endringer-i-de-regionale-inndelingene) (in Norwegian)
* [Classification of municipalities](https://www.ssb.no/en/klass/klassifikasjoner/131/)
Wikipedia has a relevant article:
* [Wikipedia:Norske kommunenummer](https://no.wikipedia.org/wiki/Norske_kommunenummer) (in Norwegian)