Make variable with several categories
Numerical variables measuring amounts, percentages, years of age and other types of continuously values may be categorised through the generate
and replace
commands.
Example of categorization of the variable wealth
where the new variable wealth_int
places the values among 4 mutually exclusive categories:
1: 0 – 500000
2: 500001 – 1000000
3: 1000001 – 1500000
4: 1500001 and over
//Connect to datastore
require no.ssb.fdb:13 as db
create-dataset demography
import db/INNTEKT_BRUTTOFORM 2019-12-31 as wealth
//Group wealth into 4 intervals
generate wealth_int = 1
replace wealth_int = 2 if wealth > 500000
replace wealth_int = 3 if wealth > 1000000
replace wealth_int = 4 if wealth > 1500000
tabulate wealth_int