Using functions for row/variabel 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:3 as db
create-dataset colrowtest
import db/BOSATTEFDT_BOSTED 2016-01-01 as residence
sample 10000 1234
import db/BEFOLKNING_KJOENN as sex
import db/INNTEKT_WLONN 2016-01-01 as salary16
import db/INNTEKT_WLONN 2017-01-01 as salary17
import db/INNTEKT_WLONN 2018-01-01 as salary18

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

//Find the highest annual salary for each individual over the years 2016-2018
generate maxsalary16_18 = rowmax(salary16,salary17,salary18)
summarize maxsalary16_18