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

st: RE: help with functions and expression: any ideas?


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: help with functions and expression: any ideas?
Date   Tue, 14 Sep 2004 13:34:37 +0100

Try 

. bysort urno (date) : gen newvar = sum(date != date[_n-1]) 

Nick 
[email protected] 

Kevan Polkinghorne

> I have a dataset as shown with a unique id no (urno) and a date of an
> episode of interest. As can be seen there can be 'multiple 
> episodes' for
> each unique id but also multiple episodes on the same date for each
> unique id. I want to create an identifier (new variable below) that
> labels each date as a separate episode for each patient (ie 
> 1,2,3...) but
> not for the same date. For two episodes on the same date I would like
> the same number to be allocated (see below id 10069 & 166056):
> 
> Data set sorted for id and date
> 
> +---------------------+
> urno        date 			new variable
> ---------------------
> 1.    29665   09 Mar 93 		1
> 2.    29665   19 May 93 		2
> 3.    29665   09 Aug 93 		3
> 4.    29665   05 Mar 94 		4
> 5.    29665   20 Apr 94 		5
> ---------------------
> 6.    29665   27 Jul 94 		6
> 7.    29665   07 Jan 95 		7
> 8.    78602   09 Jun 92 		1
> 9.    78602   07 Jul 92 		2
> 10.   100069   11 Mar 99 		1
> ---------------------
> 11.   100069   06 Apr 99 		2
> 12.   100069   06 Apr 99 		2
> 13.   131608   15 Oct 02 		1
> 14.   145132   30 Aug 01 		1
> 15.   145132   20 May 02 		2
> ---------------------
> 16.   166056   16 Jun 92 		1
> 17.   166056   26 Jul 94 		2
> 18.   166056   27 Mar 95 		3
> 19.   166056   09 Mar 98 		4
> 20.   166056   09 Mar 98 		4
> ---------------------
> I hope this all makes sense. Does anyone know a way of doing 
> this? Tried
> explicit subscripting but can seem to do exactly what I want. 
> Unable to
> find any clue for archives or stata FAQ.

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