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: ntimeofday-- format and calculation problems with date and time


From   "Joseph Coveney" <[email protected]>
To   <[email protected]>
Subject   st: Re: ntimeofday-- format and calculation problems with date and time
Date   Sun, 20 Feb 2011 14:48:10 +0900

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/


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