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: First date


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: First date
Date   Thu, 31 Jan 2013 12:05:40 +0000

I discussed the misconception that changing the format of a date or
time or date-time recasts to a different basis
in the latest Stata Journal. To convert a date from one unit to
another, you need a conversion, not a format change.

Nicholas J. Cox
Stata tip 113: Changing a variable's format: What it does and does not mean
The Stata Journal
Volume 12 Number 4: pp. 761-764

See also point 3 in this recent posting

http://www.stata.com/statalist/archive/2013-01/msg00893.html

Nick

On Thu, Jan 31, 2013 at 11:55 AM, Nick Cox <njcoxstata@gmail.com> wrote:
> To put it more simply: -ndate_added- looks like a daily date. You need
> to convert that to a date-time in milliseconds before you can add it
> to the time of day in milliseconds. The factor is 24 * 60 * 60 * 1000.
>
> Nick
>
> On Thu, Jan 31, 2013 at 11:53 AM, Nick Cox <njcoxstata@gmail.com> wrote:
>> Date-times for dates and times around now are in trillions (10^12 or
>> so) of milliseconds
>>
>> . di %14.0f clock("02-Sep-2012 10:30:14", "DMYhms")
>>  1662201014000
>>
>> so something is wrong with your variable -ndate_added-, because the
>> values you have are far too small.
>>
>> More generally, what you should be doing is to add
>>
>> date-time in milliseconds = date in milliseconds + time of day in milliseconds
>>
>> but I guess what you are doing is adding
>>
>> date-time in milliseconds = date in some other units + time in milliseconds
>>
>> which won't work.
>>
>> Note also that whatever display format you assigned to -ndate_added-
>> is quite immaterial; it's the numeric values underneath that format
>> that your calculation uses.
>>
>> Nick
>>
>> On Thu, Jan 31, 2013 at 11:31 AM, Keniajin Wambui <kiangati@gmail.com> wrote:
>>> I am using stataIC 12.1 64bit on windows 7.
>>> I am calculating the first date the values for a given serial number
>>> given was entered
>>> The data example is
>>>
>>> time_done    ndate_added    serialNumber    dfst
>>> 8:01:50 PM    26-Feb-09    88358        72127954
>>> 4:56:27 PM    27-Feb-09    88358        61004955
>>> 12:30:27 PM    25-Mar-09    88358        45044981
>>> 10:30:14 PM    02-Sep-12    88358        81033238
>>>
>>>
>>> I am using the following code but its giving me (12:30:27 PM
>>> 25-Mar-09    88358)  as the first data to be entered but according to
>>> the data (8:01:50 PM    26-Feb-09    88358) was the first to be
>>> entered.
>>>
>>>     gen double timefst=clock(time_done, "hms")
>>>     replace timefst=clock(time_done, "hm") if timefst==.
>>>     format timefst %tc
>>>     format ndate_added %tc
>>>     gen dfst=ndate_added + timefst
>>>     egen double fdoadd = min(dfst), by(serialNumber)
>>>
>>> how can I solve the problem
*
*   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