Grouping observations in Stata | Johan Osterberg - Product Engineer

Grouping observations in Stata

April 28, 2019

Sometimes you need to split a variable into groups. There are several ways to achieve this in Stata, in this post we'll use the egen command. egen stands for extensions to generate and is used mainly for more advanced operations than can be handled with the gen command. We'll look more at the egen command in another post.

Using the nlsw88 training dataset we'll split the wage variable in 3 groups, like so:

sysuse nlsw88, clear 
egen wage_group = cut(wage), group(3)
tab wage_group

Here we generated a variable wage_group consisting of three roughly equally sized groups of wage.

Result of generating grouped variable


Profile picture

Written by Johan Osterberg who lives and works in Gothenburg, Sweden as a developer specialized in e-commerce. Connect with me on Linkedin

2024 © Johan Osterberg