Using functions for row/variable calculations

Below we demonstrate how to create variables that contain the result of various calculations on row level. Row functions perform calculations at the individual level, across selected variables.

This is just a small bunch of all available row functions. Use the help-function command to get an overview of other functions.

require no.ssb.fdb:13 as db

create-dataset rowtest
import db/BEFOLKNING_KOMMNR_FAKTISK 2016-01-01 as municipality
sample 10000 1234
import db/BEFOLKNING_KJOENN as gender
import db/INNTEKT_WLONN 2016-01-01 as wage16
import db/INNTEKT_WLONN 2017-01-01 as wage17
import db/INNTEKT_WLONN 2018-01-01 as wage18

//Merge string values
generate firstname = 'Ole' if gender == '1'
replace firstname = 'Kari' if gender == '2'
generate lastname = 'Hansen'
generate name = rowconcat(firstname, ' ', lastname)
tabulate name

//Find the highest annual salary for each individual over the years 2016-2018
generate maxwage16_18 = rowmax(wage16, wage17, wage18)
summarize maxwage16_18