Skip to main content

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:23 as db

//Create a dataset containing a wage variable
create-dataset percentiletest
import db/INNTEKT_WLONN 2021-01-01 as wage21

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

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

textblock
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.
endblock

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

//Test the percentile and quartile divisions up against each other
tabulate percentile21 quartile21

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