Skip to main content

3.2.1 Automatic recoding by uploading delimited files

In cases where you want to recode many variable values, e.g. recode all municipal codes and replace them with codes for centrality, or recode from one industry standard to another, it will be time consuming and cumbersome to enter each individual code in a recode expression. Such expressions will typically form many lines depending on how many codes are to be recoded.

In microdata.no there is a solution for this. By clicking on the arrow symbol at the bottom left of the script window, a dialog box will appear that allows you to upload a delimited file that you have previously downloaded from e.g. Statistics Norway's standard classification page: www.ssb.no/klass

The specifications for the transcoding files can be found in the explanation in the dialog box. Among other things, the file must be of the semicolon-separated type (.csv), and have four columns that contain the following:

  • From code

  • From name (label)

  • To code

  • To name (label) (optional)

The functionality is adapted to Statistics Norway's standard correspondence files, but you can also use other files or create your own, as long as they have the correct format and structure.

After the file is uploaded, you will see a preview of what the transcoding will look like when it is entered into the script. If it looks right, click the "Lim inn i skript" ("Paste into script") button:

You will now see an automatically generated recode expression at the bottom of your active script, and all you need to do afterwards is replace the default variable name "variable" with the name of the variable you want to recode:



How to download correspondence files from Statistics Norway

Step 1: Go to www.ssb.no/klass

Step 2: Select the topic you want to retrieve the transcoding file from, e.g. "Classification of municipalities" which you will find under "Region"

Step 3: Select the tab "Correspondences" and then the transcoding you are interested in, e.g. "Centrality 2020"

Step 4: This table changes from centrality code to municipal code. If you want to code the opposite way, i.e. from municipal code to centrality code, click on "Invert table"

Step 5: You now have a table that recodes from municipal codes to centrality code. This can be downloaded by clicking on "Download CSV". Select the appropriate storage area on your PC and retrieve the file when you are in the file upload dialog box in the script window.


\rhd Practical example of automatic recoding of municipal codes through uploading an SSB file

TIP

If you want to recode in the opposite direction (inverted), e.g. from municipality to economic region instead of the other way around, one method is to select "Invert recoding" before downloading the code from SSB's website.

Alternatively, you can change the column names in the finished downloaded csv file. Standard column naming is as follows:

Inversion can be easily done by changing the column names in the first line like this: targetCode ; targetName ; sourceCode ; sourceName

Only the column names need to be changed. The codes below can be left as they are.