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: ntimeofday-- format and calculation problems with date and time
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: Re: ntimeofday-- format and calculation problems with date and time
Date
Sun, 20 Feb 2011 08:48:25 +0000
-ntimeofday- (SJ) was a home-grown attempt to support dates and times
before official Stata did. As soon as StataCorp provided proper
support for dates and times, it become obsolete. Phut!
Also, -ntimeday- does not support milliseconds as units, but at best
as fractions of units, and although it supports a variety of
approaches to holding dates and times, it was not prescient enough to
set up Stata's approach before that was introduced.
Alison is converting to units of days and then trying to match to
Stata's units of milliseconds and that won't work without an extra
multiplication of 1000 * 60 * 60 * 24.
As Joseph rightly advises, use -clock()- directly if your Stata supports it.
Nick
On Sun, Feb 20, 2011 at 5:48 AM, Joseph Coveney <[email protected]> wrote:
> Alison McCarthy wrote:
>
> I have imported dates and time from excel and wish to convert these into a
> format suitable for analysis. My variables read as follows:
>
> ID arrivaltime Outcome3 19/02/2011 22:20 injury
> My end-goal is to do a survival analysis, but to do this, I believe I need to
> convert variables into the stata date/time formats.
> The program that seems to handle the above best if Nick Cox's "ntimeofday"
> The variable I generate using this formulation is:
> ntimeofday arrivaltime, gen(ARRIVED) s (dmy h min) n(day) cend(2050).
> I have then tried to format the new variable into:
> dd-mm-yyyy hh-mm
> However, I cannot seem to make this work. If anyone could tell me what I am
> doing wrong I would be most grateful.Best
>
> --------------------------------------------------------------------------------
>
> Try the following (at the "Begin here"; the first part sets up the data).
>
> Joseph Coveney
>
> version 11.1
>
> clear *
> set more off
>
> input str1 ID str16 arrivaltime str6 Outcome
> "3" "19/02/2011 22:20" "injury"
> end
>
> *
> * Begin here
> *
> help dates_and_times
>
> generate double timearrived = clock(arrivaltime, "DMYhm")
> format timearrived %tc
> list
>
> exit
*
* 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/