7 Listing and Sorting

7.1 Listing cases

To list data in the main results window you use the list command. If you type

list maths english

on the console, Stata will respond by listing all observations for those variables. If you don’t specify variables Stata uses all the variables.

7.2 Exercise

Type following line on the console

list maths class in 1/6

How would you describe the effect of the modifier in 1/6

7.3 Sorting

The most basic sort command in Stata is sort. This command sorts on a list of variables (at least one) in ascending order. Run this code in the command window

sort sex maths

If you list the data now and scroll through the output, you will see it is sorted first by sex ascending and then by maths ascending. While useful, there is a more flexible command for sorting values.

7.4 gsort

The command gsort also sortson on a list of variables, but you can determine the order by prefixing a variable name with + for ascending order or - for descending order. Try the following in the command window

gsort +sex -class - maths

Again you should list and scroll and note effect.