Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: First visit to clinic


From   "Paul O'Brien" <paul.obrien@afe2.org.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: First visit to clinic
Date   Mon, 20 Sep 2010 17:26:41 +0100

yes, saw the missing colon in Neil's comments, which apart from the missing colon gives me just what i want.

bysort id_c (date_v): gen firstever= date_v[1]
format  firstever %dD/N/Y

	+---------------------------------+
	id_c     date_v   firste~r 
	---------------------------------
1000.	N-00-3485   02/04/07   02/04/07 
1001.	N-00-3485   06/09/07   02/04/07 
1002.	N-00-3485   12/06/08   02/04/07 
1003.	N-00-3485   08/02/10   02/04/07 
	---------------------------------
1004.	N-00-3498   21/11/07   21/11/07 
1005.	N-00-3498   12/03/10   21/11/07 
	---------------------------------
1006.	N-00-350   17/04/07   17/04/07 
	---------------------------------
1007.	N-00-3505   30/08/07   30/08/07 
	---------------------------------
1008.	N-00-3519   04/09/08   04/09/08 
1009.	N-00-3519   02/09/09   04/09/08 


thanks Neil and Martin.

paul

On 20 Sep 2010, at 17:09, Martin Weiss wrote:

> 
> <>
> 
> Careful, though, Neil`s command seems to be lacking a colon after 
> 
> - bysort id (date)-...
> 
> 
> HTH
> Martin
> 
> 
> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Neil Shephard
> Sent: Montag, 20. September 2010 15:29
> To: statalist@hsphsun2.harvard.edu
> Subject: Re: st: First visit to clinic
> 
> On Mon, Sep 20, 2010 at 1:24 PM, Paul O'Brien <paul.obrien@afe2.org.uk>
> wrote:
>> i want to create a new variable with the date of the first visit of each
> patient:
>> 
>> id              date            date_of_first_visit
>> N-00-3558       07/04/2008      07/04/2008
>> N-00-3558       09/04/2008      07/04/2008
>> N-00-3558       14/05/2008      07/04/2008
>> N-00-3563       05/06/2007
>> N-00-3563       31/03/2010
>> N-00-3565       05/06/2007
>> N-00-3565       13/06/2008
>> N-00-3565       13/06/2008
>> N-00-3565       05/05/2009
>> N-00-3565       04/03/2010
>> N-00-3583       09/09/2008
>> N-00-3583       27/05/2009
>> 
>> i know this should be easy by i am having trouble using n_1
>> 
>> i have tried:
>> .sort date
>> .by id, sort: gen visit=_n==1
>> 
>> but the latter does not have the date in order, only id.
> 
> bysort id (date) gen date_of_first_visit = date[1]
> 
> should do the trick.
> 
> Neil
> 
> -- 
> "One should as a rule, respect public opinion in so far as is
> necessary to avoid starvation and to keep out of prison, but anything
> that goes beyond this is voluntary submission to an unnecessary
> tyranny, and is likely to interfere with happiness in all kinds of
> ways..." - Bertrand Russell
> 
> Email - nshephard@gmail.com
> Website - http://slack.ser.man.ac.uk/
> Photos - http://www.flickr.com/photos/slackline/
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
> 
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/

-------------------------------
Dr Paul O'Brien
Raymede Clinic
Westside Contraceptive Services
Central London Community Healthcare
Exmoor St
London
W10 6DZ
UK
+44 (0)20 8962 4450










*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index