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: Distorted time when building SIFs from components


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Distorted time when building SIFs from components
Date   Wed, 25 Dec 2013 13:00:43 +0000

<>

Use -double- for your variable, not -float-.
Nick
[email protected]


On 25 December 2013 12:44, Milena Przheska
<[email protected]> wrote:
> Dear Statalist members,
>
> I have a dateime variable 'time' with format %tc and a 'date' variable
> with only the date. I needed a variable that will show the date and
> the hour, so that observations happening on the same date in the same
> hour would have same time stamp. Therefore, I first extracted the
> year, month and day from 'date' and hour from 'time'. Then I generated
> two separate variables with values 0, to serve as minutes and seconds.
> Finally, I build a time stamp from these components, but instead of
> getting datetime variable with zero minutes and seconds, I got a
> variable that had altered hour, minutes and second.
>
> Can anyone please let me know why this happens and how can I fix it?
>
> Commands:
>
> gen double date = dofc(time)
> format date %td
>
> gen double Y = year(date)
>
> gen double M = month(date)
>
> gen double D = day(date)
>
> gen double h = hh(time)
>
> gen double m = 0
>
> gen double s = 0
>
> gen short_time = mdyhms(M, D, Y, h, m, s)
> format short_time %tc
>
>
> Results:
>
> m    s    h      Y      M    D     short_time
> 0    0    18    2013    5    22    22may2013 17:59:21
> 0    0    14    2013    5    26    26may2013 13:59:40
> 0    0    6     2013    5    4     04may2013 05:58:58
> 0    0    20    2013    5    9     09may2013 20:00:14
> 0    0    2     2013    6    5     05jun2013 01:59:13
> 0    0    6     2013    7    8     08jul2013 05:59:40
> 0    0    6     2013    7    8     08jul2013 05:59:40
>
>
> I would appreciate your help.
>
> Thank you,
> Milena
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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