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]

RE: st: RE: Delta of two time variables (%tc) in minutes


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: RE: Delta of two time variables (%tc) in minutes
Date   Thu, 21 Oct 2010 15:19:25 +0100

No offen{c|s}e taken, but more can be said. 

I think that elapsed times (delta t) always need to be handled separately from date-times. Thus the time I take to do something 

5 min 

is quite distinct logically from a date time 

5 min, meaning in Stata "5 min after midnight on Jan, 1, 1960". 

This is inescapable and the difference can not be blamed on any software! 

More positively put, you don't need separate functions for elapsed times, as usually unit conversions are just simple arithmetic. 

But everyone agrees, I imagine: dates and times are a pain. 

(At one point, I could not wait for StataCorp "to do it properly" so I did it myself, in terms of writing commands that did what I wanted:  

SJ-6-1  dm0018  . . . . . . . . . . . . . . . . .  Speaking Stata: Time of day
        (help ntimeofday, stimeofday if installed)  . . . . . . . .  N. J. Cox
        Q1/06   SJ 6(1):124--137
        converting back and forth between string and numeric
        representations for time-of-day calculations

Then StataCorp made my commands obsolete just a short while later by adding a much more comprehensive set of functions.) 

But if you think about it, do you want _more_ functions for special purposes? That would just add to the documentation! 

Nick 
[email protected] 

Kaspar Dardas

Hey Nick,

as usual, thanks for your suggestion. It was all gold and exactly what
I was looking for. Well, you have identified my problem correctly (my
"constants" were stored as doubles in %tc format etc...) and my
solution was something like 1.603e+12 regardless of my poor
description- sorry.

On a side note I was actually thinking of a similar solution, however,
I thought that a sophisticated statistical Software handle this better
(something like the delta(min) option in tsset). No offense please.
Still lovin Stata 11... but "time & date" issues are always a pain for
and I feel that I waste too much time on it....

2010/10/21 Nick Cox <[email protected]>:

> We can't tell you what you are doing wrong if you don't show us any of your solutions.
>
> On a fundamental point: a variable's (or constant's) format is not a matter of how numbers are stored; it is a matter of how they are displayed. You may know that really, but it's still a misuse of terms to talk that way.
>
> This area is one with lots of detail which probably no-one remembers unless they use these functions all the time. I don't either, and each time I have a new question it can be a few minutes with the help before I find what I want.
>
> But I have some very simple tips on how to find out.
>
> 1. A golden thread linking date-times is that Stata counts (not measures) time, so works with integers, and the units are ms (milliseconds).
>
> 2. To check what is being done, fire up -display- and contrive examples to which you know the answer.
>
> 3. Use -display- with formats that make sense. The default is not helpful
>
> . di tc(21oct2010 12:00)
> 1.603e+12
>
> So I use plenty of space and use my knowledge that time is an integer
>
> . di %21.0f  tc(21oct2010 12:00)
>        1603281600000
>
> In this example I know that the answer must be 5 minutes
>
> . di %21.0f  tc(21oct2010 12:00) - tc(21oct2010 11:55)
>               300000
>
> And I can reproduce that by dividing by 60,000. (Evidently there are 60,000 ms in a minute.)
>
> . di %21.0f  (tc(21oct2010 12:00) - tc(21oct2010 11:55))/60000
>                    5
>
> There are probably quicker ways, which will trump this solution. But the short answer to your question may be as simple as divide by 60000.

Kaspar Dardas
>
> a quick question on the delta units of two time variables stored in
> %tc format. How do I get the delta of
> publishtime - local_time in minutes elapsed (not HH:MM etc... but
> simply in minutes as numbers)?
> At first sight this seems pretty simple (I am sure it is for the most
> of you) but I cant get it right and the time and date help section in
> the manual drives me virtually crazy.
>
> publishtime               local_time
> 19jun2007 12:20:00      19jun2007 12:11: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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index