Diff-in-diff analysis

In the example below, a diff-in-diff analysis is run.

First, a random sample of 100,000 individuals is drawn. This is optional, it is entirely possible to run the analysis on full populations. A panel data set is then created for this sample using import-panel, and data is imported for the years 2018 – 2021. Afterwards, the panel data set is balanced by deleting all observations with at least one missing value (optional).

The group variable is then coded, using women as the treatment group and men as the control group. The processing date is set for 2020.

Finally, the command regress-panel-diff is executed, and you get the diff-in-diff value (ATET) -1991.77 when you control for marital status = married, place of residence = Oslo, and educational level equal to a master’s degree or higher. The ATET value is not significant in this case.

require no.ssb.fdb:23 as db

//Create a random sample of 100000 individuals
create-dataset population
import db/BEFOLKNING_KJOENN as gender
sample 100000 3322
clone-units population paneldata

//Create a panel dataset for the random population
use paneldata
import-panel db/INNTEKT_LONN db/SIVSTANDFDT_SIVSTAND db/BOSATTEFDT_BOSTED db/BEFOLKNING_KJOENN db/NUDB_BU 2018-01-01 2019-01-01 2020-01-01 2021-01-01
rename INNTEKT_LONN wage
rename SIVSTANDFDT_SIVSTAND civstat
rename BOSATTEFDT_BOSTED municipality
rename BEFOLKNING_KJOENN gender
rename NUDB_BU edu

//Balance the panel dataset
drop if sysmiss(wage) | sysmiss(civstat) | sysmiss(municipality) | sysmiss(gender) | sysmiss(edu)

//Create group and treatment variables (required)
generate group = 0
replace group = 1 if gender == '2'

generate treatment = 0
replace treatment = 1 if year(date@panel) >= 2020

//Recode other explanatory variables
generate married = 0
replace married = 1 if civstat == '2'

generate oslo = 0
replace oslo = 1 if municipality == '0301'

generate high_edu = 0
replace high_edu = 1 if substr(edu,1,1) == '7' | substr(edu,1,1) == '8'

//Run diff-in-diff analysis
summarize-panel wage if group == 1
summarize-panel wage if group == 0

regress-panel-diff wage group treatment married oslo high_edu