How to use eventdata to find persons who have divorced during a year

The example below demonstrates how to use the import-event command to create an event-dataset that can be used to find people who have divorced (records with sivil status = ‘4’) during a specific year.

This procedure may also be used in all similar cases where the goal is to find persons with a spesific value measured over a time span.

//Connect to datastore
require no.ssb.fdb:23 as ds

//Create a population consisting of all residents in Norway per 2021-01-01
create-dataset totalpop
import ds/BEFOLKNING_KJOENN as gender
import ds/BEFOLKNING_STATUSKODE 2021-01-01 as regstat
keep if regstat == '1'

//Find persons with divorce status during the previous year (2020)
create-dataset events
import-event ds/SIVSTANDFDT_SIVSTAND 2020-01-01 to 2020-12-31 as siv_events
keep if siv_events == '4'
collapse (count) siv_events, by(PERSONID_1 )
rename siv_events divorces
tabulate divorces

//Link divorce data onto the main residents dataset and creating a dummy variable indicating divorced status
merge divorces into totalpop
use totalpop
generate divorced2020 = 0
replace divorced2020 = 1 if divorces >= 1
tabulate divorced2020, cellpct
piechart divorced2020