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]

st: RE: Re: question about working with dates and times


From   "Visintainer, Paul" <Paul.Visintainer@baystatehealth.org>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Re: question about working with dates and times
Date   Tue, 27 Jul 2010 07:59:49 -0400

Thanks, Joe.  I think I get it.  Rather than just specifying the interval, one specifies the desired interval from the zero-point.

-p
________________________________________________
Paul F. Visintainer, PhD
Baystate Medical Center
Springfield, MA 01199



-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Joseph Coveney
Sent: Monday, July 26, 2010 9:58 PM
To: statalist@hsphsun2.harvard.edu
Subject: st: Re: question about working with dates and times

Paul Visintainer wrote:

I'm having a little difficulty working with dates and times as doubles.  I want
to add to an existing date an interval that is 24 hours (or even larger).  The
following code works:

.gen double day0 = tc("06oct2007 00:00:00")     // e.g., existing date   (1)

.gen double day1 = day0 + tc(23:59:59) + tc(00:00:01)  // 24-hr interval (2)

.format day0 day1 %tc

.list day0 day1 in 1

     +-----------------------------------------+
     |               day0                 day1 |
     |-----------------------------------------|
  1. | 06oct2007 00:00:00   07oct2007 00:00:00 |
     +-----------------------------------------+

But, step 2 seems cumbersome (because tc(24:00:00) is an invalid value.)

When working with dates/times as doubles, I suspect there is a simpler approach
for adding large intervals (e.g., 36 hours, or 2 weeks, or 3 months, etc).  Any
help would be appreciated.

--------------------------------------------------------------------------------

Use Stata's base date-time, midnight, January 1, 1960, as the zero-point in the 
increment.

Joseph Coveney

. generate double day0 = tc("06oct2007 00:00:00")

. generate double day1 = day0 + ///
>     tc("02jan1960 00:00:00")

. generate double day2 = day0 + ///
>     tc("02mar1960 00:00:00")

. format day0 day1 day2 %tc

. list day0 day1 day2 in 1

     +--------------------------------------------------------------+
     |               day0                 day1                 day2 |
     |--------------------------------------------------------------|
  1. | 06oct2007 00:00:00   07oct2007 00:00:00   06dec2007 00:00:00 |
     +--------------------------------------------------------------+



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

----------------------------------------------------------------------
Please view our annual report at http://baystatehealth.org/annualreport
 

CONFIDENTIALITY NOTICE: This e-mail communication and any attachments may contain confidential and privileged information for the use of the designated recipients named above. If you are not the intended recipient, you are hereby notified that you have received this communication in error and that any review, disclosure, dissemination, distribution or copying of it or its contents is prohibited. If you have received this communication in error, please reply to the sender immediately or by telephone at 413-794-0000 and destroy all copies of this communication and any attachments. For further information regarding Baystate Health's privacy policy, please visit our Internet site at http://baystatehealth.org.

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