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: Delta of two time variables (%tc) in minutes


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

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. 

Nick 
[email protected] 

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