Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Search for dates within range


From   "Hillgrove, Tessa (SA)" <[email protected]>
To   [email protected]
Subject   RE: st: Search for dates within range
Date   Thu, 18 May 2006 13:58:40 +1000

Thanks Nick! 
Spoilt for choice now.... 

-----Original Message-----
From: Nick Cox [mailto:[email protected]] 
Sent: Wednesday, 17 May 2006 6:14 PM
To: [email protected]
Subject: RE: st: Search for dates within range

A twist on this is use -inrange()-

... if inrange(date, mdy(4,1,2003), mdy(5,31,2003))

or for that matter -twithin()-. 

Type

help inrange()

or 

help twithin()

Nick
[email protected] 

Hillgrove, Tessa (SA)
 
> Thanks Austin

Austin Nichols 
 
> It's easy if you put dates in the right format... see -help
> dates- and -help
> date functions-
> 
>  gen date=date(dstr,"dmy")
>  format date %d
>  gen inwindow=date>=mdy(4,1,2003) & date<mdy(6,1,2003)  egen 
> anyinw=max(inwi), by(id)  li, noo
> 
>   +----------------------------------------------------------------+
>   | id         dstr           type        date   inwindow   anyinw |
>   |----------------------------------------------------------------|
>   |  1   01-01-2003     Successful   01jan2003          0        1 |
>   |  1   01-05-2003     Successful   01may2003          1        1 |
>   |  2   01-03-2002       Deferred   01mar2002          0        0 |
>   |  2   31-12-2003   Unsuccessful   31dec2003          0        0 |
>   +----------------------------------------------------------------+
 
Hillgrove, Tessa 

> > My dataset is in the following format
> > ID      Attend Date     Type
> > 1       01-01-2003      Successful
> > 1       01-05-2003      Successful
> > 2       01-03-2002      Deferred
> > 2       31-12-2003      Unsuccessful
> >
> > I have two "problems" with my dataset : (1) I have more
> subjects than
> > I need and (2) and a wider range of attendance dates than I need.
> > I am trying to identify subjects that had an appointment on
> any dates
> > within a two month range.
> > I will drop all respondents who do not.
> > Of the respondents that did have an appointment, I will
> need to only
> > consider attendance within a specific range (and drop the
> remainder).
> > Any ideas of how to do this?

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



E-mail Disclaimer:
Any personal information in this e-mail must be handled in accordance with
the provisions of the Privacy Act 1988 [Cth].  The information contained in
the e-mail may be confidential and if the person receiving the e-mail is not
the intended recipient they should immediately advise ARCBS by e-mail
response to the ARCBS sender and then deal with the e-mail as directed by
ARCBS. The views expressed in the e-mail are those of the individual sender
unless otherwise stated to be the views of ARCBS. No warranties are provided
that the e-mail is computer virus or other defect free.
*
*   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