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: question about working with dates and times
From
"Joseph Coveney" <[email protected]>
To
<[email protected]>
Subject
st: Re: question about working with dates and times
Date
Tue, 27 Jul 2010 10:58:25 +0900
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/