Make variable with more than two categories

Numerical variables measuring amounts, percentages, years of age and other types of continuously values may be categorised through the commandos generate and replace.

Example of categorization of the variable wealth where the new variable wealthint places the values among 4 mutually exclusive categories:

1: 0 - 150000

2: 150001 - 250000

3: 250001 - 400000

4: 400001 and over

//Connect to databank
require no.ssb.fdb:1 as fdb1

create-dataset demografidata
import fdb1/INNTEKT_BRUTTOFORM 2000-01-01 as wealth

//Group wealth into 4 intervals
generate wealthint = 1
replace wealthint = 2 if wealth > 150000
replace wealthint = 3 if wealth > 250000
replace wealthint = 4 if wealth > 400000