Scott,
Thanks very much for this!
Steve
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Scott
Merryman
Sent: 23 January 2005 20:42
To: [email protected]
Subject: st: RE: Creating an id that is incremented by the value taken
by another variable
How about something like this:
. l, ab(12) noobs
+--------------------------------+
| id epi_order end_of_spell |
|--------------------------------|
| 101 1 0 |
| 101 2 0 |
| 101 3 1 |
| 101 1 0 |
| 101 2 1 |
|--------------------------------|
| 102 1 1 |
| 102 1 1 |
| 102 1 1 |
+--------------------------------+
. gen seeking = sum(end) + 1 - end
. l, ab(12) noobs
+------------------------------------------+
| id epi_order end_of_spell seeking |
|------------------------------------------|
| 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 |
+------------------------------------------+
Scott
> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of SD Martin
> Sent: Sunday, January 23, 2005 1:40 PM
> To: [email protected]
> Subject: st: Creating an id that is incremented by the value taken by
> another variable
>
> 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/
*
* 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/