How to group income values into percentiles, deciles and quartiles

This example demonstrates how to convert from income values measured as amounts into divisions like percentiles, deciles and quartiles. It also shows how to controle the outcome of the conversion.

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

//Create a dataset containing a wage variable
create-dataset percentiletest
import db/INNTEKT_WLONN 2019-01-01 as wage19

//Produce wage statistics measured in 2019 (all individuals with positive wage income this year)
summarize wage19
histogram wage19

//Convert into percentiles and test the division
generate percentile19 = quantile(wage19, 100)
histogram percentile19, discrete

NB! Note that the 1st percentile is fusioned with the 2nd due to the 1% bottom coding. This will sometimes happen if the 1st percentile is slightly below the 1% limit (0.99). In principle, this will also be the case for the last percentile (100th) due to the 1% top coding.

//Convert into quartiles and test the division
generate quartile19 = quantile(wage19, 4)
histogram quartile19, discrete

//Test the percentile and quartile divisions up against each other
tabulate percentile19 quartile19

//Convert into deciles and show the frequencies and means within each decile
generate decile19 = quantile(wage19, 10)
tabulate decile19, missing
tabulate decile19, summarize(wage19)