I have some hospital data based on episodes of care (one record per
episode). There a patient identifier (id) and an episode order
identifier (so that the records can be sorted into chronological order
by patient).
Episodes can be grouped into spells of care and there is a third
variable (endofspell) which denotes the last episode in a particular
spell (endofspell=1).
Sorting the data by id and epiorder yields:
Id EpiOrder Endofspell Seeking this variable
101 1 0 1
101 2 0 1
101 3 1 1
101 1 0 2
101 2 1 2
102 1 1 3
102 1 1 4
102 1 1 5
Generate id =_n attaches an observation number to each episode but I
want to do this for each spell, as shown above by 'seeking this
variable'. This is incremented by 1 each time endofspell=1.
Thanks.
Steve
*
* 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/