Bysort Stata. Gen ea tag1 n 1. Byscan be used with explicit subscriptingto create new variables in all kinds of useful way.
Then for observations with common var1 stata will sort them according to var2. Stata r free download as pdf file pdf text file txt or view presentation slides online. One observation in each ea.
Let s illustrate use of the process using the high school and beyond dataset.
Generate n n list if n 1. Stata has two system variables that always exist as long as data is loaded n and n. Below is a simplified version of the code that will yield the exact same results as above. Check first that egendoesn t already have what you want.