Track code changes

You have to download the files from SSB and save it as a csv file. For the code changes, they have to be copied and pasted into an Excel file. These code changes can be found under Endringer tab in the website. It’s advisable to name the file with a specific word to differentiate the file from the csv files. I would recommed to add the word change. For example fylke_change_jan2018.xlsx and the downloaded csv file will be fylke_jan2018.csv. It’s also advisable to add the year to all files to easily differentiate them when running the code. Check the suggested structure here for naming files.

Add changes

The geo_set() function is the most important function to start with. This function will create an object that is easily used by other available functions in norgeo. This is where raw data in csv and xlsx formats will be merged. Additional information will also be added. The codes below show how the function is used:

## specify the folder where kommune files are
folder <- "F:/org/kommune"

kom2018 <- geo_set(grep.file = "jan2018",
                   grep.change = "change",
                   year = 2018,
                   type = "kommune",
                   folder.path = folder)

kom2019 <- geo_set(grep.file = "jan2019",
                   grep.change = "change",
                   year = 2019,
                   type = "kommune",
                   folder.path = folder)

kom2020 <- geo_set(grep.file = "jan2020",
                   grep.change = "change",
                   year = 2020,
                   type = "kommune",
                   folder.path = folder)

Merge changes

To merge all these files into a big dataset, use geo_merge() function. Important to note that input for geo_merge() must be a list and they are arranged from oldest to most recent codes. Available output includes:

  • all : All merged codes. This is the default
  • change : Only codes that have changed
  • split : Codes that have been divided to at least two codes in the current list
  • merge : At least two codes are merged into one in the current list
komfiles <- list(kom2018, kom2019, kom2020)
DF <- geo_merge(files = komfiles)

# show only codes that have changed
DFS <- geo_merge(files = komfiles, output = "split")

Save codes

The output created from geo_merge() i.e DF, can be saved in a database management system (DBMS) which include Access and SQLite, or as ordinary files such as Excel or text file.

fpath = "C:/Users/ybka/dbms"

geo_save(tblname = "tblTest",
         obj = DF,
         des.path = fpath,
         file.type = "Excel")

When saving as a table in a DBMS, a database file must be available prior to saving it. In the example below the object is saved as a table to an Access database geo_ssb.accdb.

dbpath = "C:/Users/ybka/dbms"
dbname = "geo_ssb.accdb"

geo_save(tblname = "tblGeo",
         obj = bigDF,
         des.path = dbpath,
         file.type = "Access",
         db.name = dbname)