Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: RE: Date from Intial visit


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: Date from Intial visit
Date   Wed, 26 Jan 2011 19:30:02 +0000

Again, one has to guess whether this is a string variable or a daily date held as a numeric variable. You said it was similar to the previous, so I'll take it as string. 

But this isn't so easy. What's 6 months from 31 August? It's not 31 February! 

But here's a start: 

. set obs 1
obs was 0, now 1

. gen mydate= "6sep2008"

. gen statadate =  date("6sep2008", "DMY")

. format statadate %d

. l

     +----------------------+
     |   mydate   statadate |
     |----------------------|
  1. | 6sep2008   06sep2008 |
     +----------------------+

. gen newmonth = 6 + month(statadate)

. gen newyear = year(statadate) + (newmonth >= 13)

. replace newmonth = newmonth - 12  if (newmonth >= 13)
(1 real change made)

. gen newdate = mdy(newmonth, day(statadate), newyear)

. format newdate %d

. l

     +-------------------------------------------------------+
     |   mydate   statadate   newmonth   newyear     newdate |
     |-------------------------------------------------------|
  1. | 6sep2008   06sep2008          3      2009   06mar2009 |
     +-------------------------------------------------------+

It's often easier to say something like 25 weeks. But there will be protocols in your field that determine what people do. For example, your clinic may only be open Monday-Friday, or whatever. 

Nick 
[email protected] 


Clinton D. Bullock, RPH, NCPS, CDR, USPHS

Hi all, similar to the last question, I'm trying to get the results of a outcome (in this case smoking=0 not smoking=1) 6 months from an initial date (the patient's first clinic visit).  The date is coded in the format <10sep2008> in stata. Is it possible to do this? Thank in advance for any help.
 

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index