Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

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

 From Kaspar Dardas To statalist@hsphsun2.harvard.edu Subject Re: st: RE: Delta of two time variables (%tc) in minutes Date Thu, 21 Oct 2010 15:53:28 +0200

```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....

Again thanks a lot Nick.

Best,

Kaspar

2010/10/21 Nick Cox <n.j.cox@durham.ac.uk>:
> 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
> n.j.cox@durham.ac.uk
>
> 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/
>

--
Kaspar Dardas
Research Assistant
HCI Endowed Chair of Financial Services

EBS Universität für Wirtschaft und Recht i. Gr.

Gustav-Stresemann-Ring 3

GERMANY
Phone: +496990557616
Kaspar.Dardas@students.ebs.edu
www.ebs.edu

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