Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Creating an id that is incremented by the value taken by another variable


From   SD Martin <[email protected]>
To   <[email protected]>
Subject   st: Creating an id that is incremented by the value taken by another variable
Date   Sun, 23 Jan 2005 19:39:42 -0000

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/



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