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

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


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: Creating an id that is incremented by the value taken by another variable
Date   Mon, 24 Jan 2005 09:24:13 -0000

Another solution appears to be 

gen seeking = sum(epi_order == 1) 

In this terrain, check out also -tsspell- 
from SSC: 

tsspell, f(epi_order == 1) 

Nick 
[email protected] 

Scott Merryman

> 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 |
>   +------------------------------------------+

Steve Martin
 
> > 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.

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