Two suggestions: 
1. Do you also need a unique id? 
gen uniqueid = _n 
2. Check out the -stable- option. 
Nick 
[email protected] 
Deborah Garvey, Ph.D.
 
> I have data with a household identifier (serial) and a person 
> locator within each household (pernum).
> 
> Is there any way to maintain a sort order of PERNUM within 
> SERIAL, i.e., the results of a command like -sort serial 
> pernum-  for a -bysort- that is sorted on a within-household 
> indicator variable, i.e. -bysort serial (indicatorvar): 
> several expressions to condition the value of a PERNUM-level variable-
> 
> My question may seem odd, but the person's location in the 
> household is an important criterion for determining the 
> indicator variable's value. Unfortunately, the value of the 
> indicator variable may be the same for more than one person 
> in the household, so I can't use -bysort serial pernum 
> (indicatorvar):  stuff-
> 
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/