Merge job data into individual level datasets

The example below demonstrates how to connect data with job as unit type with another data set with person as unit type.

Job data from the so-called “A-ordningen” with the prefix “ARBLONN_ARB_” have job as unit type (i.e. up to several records per person). In order to be able to link such data with ordinary personal data sets, one must first use the collapse command to sum up the information related to each individual employment relationship per individual. The dataset then gets person as unit type (one record per person), and can thus be linked into the personal dataset “employees”.

//Connect to datastore
require no.ssb.fdb:13 as db

//Create dataset for employees (persondata)
create-dataset employees
import db/ARBLONN_PERS_KJOENN 2021-07-16 as gender
import db/ARBLONN_PERS_ALDER 2021-07-16 as age

//Create dataset for jobs (jobdata)
create-dataset jobs
import db/ARBLONN_ARB_ARBEIDSTID 2021-07-16 as workingtime
import db/ARBLONN_ARB_STILLINGSPST 2021-07-16 as percentage_fulltime
import db/ARBEIDSFORHOLD_PERSON as personid

//Aggregate from joblevel into personlevel by adding up working time per week and percentage of full-time equivalent per person. Then, link data onto the employees dataset
collapse (sum) workingtime percentage_fulltime, by(personid)
merge workingtime percentage_fulltime into employees

//Produce job statistics
use employees

summarize workingtime percentage_fulltime
tabulate gender, summarize(workingtime)
tabulate gender, summarize(percentage_fulltime)

generate agegroup = 1
replace agegroup = 2 if age > 25
replace agegroup = 3 if age > 40
replace agegroup = 4 if age > 60
define-labels agelabel 1 '0-25' 2 '26-40' 3 '41-60' 4 '61->'
assign-labels agegroup agelabel
tabulate agegroup
tabulate agegroup gender, summarize(workingtime)
tabulate agegroup gender, summarize(percentage_fulltime)