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 formue where the new variable formueint places the values among 4 mutually exclusive categories:

1: 0 - 150000

2: 150001 - 250000

3: 250001 - 400000

4: 400001 and over

create-dataset demografidata
import INNTEKT_BRUTTOFORM 2000-01-01 as formue

//Group formue into 4 intervals

generate formueint = 1
replace formueint = 2 if formue > 150000
replace formueint = 3 if formue > 250000
replace formueint = 4 if formue > 400000