You are on page 1of 2

Statistical Data Handling Tips

By Mutyaba Andrew, Statistician – Uganda Bureau of Statistics (UBoS)

Tip 1: How to categorize continuous variables


into groups using Stata
In the field of statistical analysis we are always faced with the challenge of transforming
continuous variables into groups so as to summarize the data and perform meaningful analysis.

For instance, given a set of observations of the ages of a group of people, say ranging from 10
years to 61 years. One could desire to categorize the continuous age records into five age groups
such as given below:

10 years up to (and including) 20 years


21 years up to (and including) 30 years
31 years up to (and including) 40 years
41 years up to (and including) 50 years
51 years and above

This can easily be achieved by using the command egen in combination with the function cut()
as illustrated in the example below.

The following data of age in years for eleven people is captured in Stata and saved in the file
age.dta

10, 20, 21, 30, 31, 40, 41, 50, 51, 60, 61

To view the entered data we open our data file in Stata and tabulate the frequencies as follows:

. use "C:\Users\Andrew\Desktop\age.dta"

Page 1 of 2
. tab age

age | Freq. Percent Cum.


------------+-----------------------------------
10 | 1 9.09 9.09
20 | 1 9.09 18.18
21 | 1 9.09 27.27
30 | 1 9.09 36.36
31 | 1 9.09 45.45
40 | 1 9.09 54.55
41 | 1 9.09 63.64
50 | 1 9.09 72.73
51 | 1 9.09 81.82
60 | 1 9.09 90.91
61 | 1 9.09 100.00
------------+-----------------------------------
Total | 11 100.00

We then generate a new variable called agegroup and tabulate it using the five groups as follows:

. egen agegroup = cut(age), group(5) label

. table agegroup

----------------------
agegroup | Freq.
----------+-----------
10- | 2
21- | 2
31- | 2
41- | 2
51- | 3
----------------------

. tabulate agegroup

agegroup | Freq. Percent Cum.


------------+-----------------------------------
10- | 2 18.18 18.18
21- | 2 18.18 36.36
31- | 2 18.18 54.55
41- | 2 18.18 72.73
51- | 3 27.27 100.00
------------+-----------------------------------
Total | 11 100.00

I hope you find this tip useful.


Contact: andymutyaba@gmail.com
Page 2 of 2

You might also like