Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: How Can I Create the Variable x?


From   "Jason Ferris" <[email protected]>
To   <[email protected]>
Subject   Re: st: How Can I Create the Variable x?
Date   Tue, 30 Jan 2007 10:13:09 +1100

clear
input id bsid 
1  22 
1  22 
1  52 
1  87 
2  43 
2  43 
2  11 
3  28 
4  33 
end 
bysort id : egen x=seq() if bsid~=bsid[_n-1] /* sequence starts the
ordering */
replace x=x[_n-1] if x==. /* fills in the missing gaps */


Jason Ferris
Research Officer
Australian Research Centre in Sex, Health and Society
Level 1, 215 Franklin St
Melbourne
VIC 3000
P: 61 (0)3 9285 5282
F: 61 (0)3 9285 5220

*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index