Bysort Stata. Stata r free download as pdf file pdf text file txt or view presentation slides online. Let s illustrate use of the process using the high school and beyond dataset.
Stata faq when you want to use by var. Then for observations with common var1 stata will sort them according to var2. Sort varlist if varlist is only one variable then stata will sort the observations in ascending order based on that variable.
You can use the sort command in stata to acheive this.
N basically indexes observations rows. N denotes the total number of rows. This is a handy way to make sure that your ordering involves multiple variables but stata will only perform the command on the first set of variables. N basically indexes observations rows.