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]
Re: st: working with timestamps with milliseconds
From
Michael Mitchell <[email protected]>
To
[email protected]
Subject
Re: st: working with timestamps with milliseconds
Date
Sat, 20 Feb 2010 18:17:42 -0800
Dear David
Ah, you have been bitten by the need to store date/time values as
-double- precision variables. Otherwise, as you see, precision is
lost. So, you would instead specify
gen double time2 = clock(time, "MDY hms")
and that should work for you.
Best regards,
--
Michael N. Mitchell
See the Stata tidbit of the week at...
http://www.MichaelNormanMitchell.com
Visit me on Facebook at...
http://www.facebook.com/MichaelNormanMitchell
On Sat, Feb 20, 2010 at 5:29 PM, David Souther
<[email protected]> wrote:
> I couldn't find a solution to this in the Statalist archives, and this
> may be in the dates/times help file but I've read through it a couple
> of time and cannot find (or probably don't understand this file enough
> to find) the solution for how to work with milliseconds.
> Every time I format a timestamp that includes the MDY along with
> hours, minutes, seconds and milliseconds, the seconds/milliseconds are
> off by a minute or so. I did see the section on leap seconds, but I"m
> not sure how that plays into my example and if there is a way to just
> show and work with the exact timestamp that I input into Stata.
> Here's what I do
>
> clear
> inp str30 time
> "1-22-2007 3:44:22"
> "1/23/2008 02:23:11.11"
> end
>
> gen time2 = clock(time, "MDY hms")
> format time2 %tC
>
> gen d2 = clock("2/22/2002 14:22:33.232", "MDY hms")
> format d2 %tc
>
>
> This gives me --
>
> +-----------------------------------------------------------------+
> | time time2 d2 |
> |-----------------------------------------------------------------|
> 1. | 1-22-2007 3:44:22 22jan2007 03:43:35 22feb2002 14:23:02 |
> 2. | 1/23/2008 02:23:11.11 23jan2008 02:23:17 22feb2002 14:23:02 |
> +-----------------------------------------------------------------+
> Notice that the time changed in from things like 3:44:22 to 3:43:35.
>
> I tried using %tC as well. I use Stata 11 on Windows. Any hints?
>
> Thanks,
>
> David
> *
> * 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/