Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Time of day


From   "Marc N. Schüssler" <marc.schuessler@medma.uni-heidelberg.de>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Time of day
Date   Thu, 28 Aug 2008 14:58:29 +0200

Hi Alexander,
i suggest you to get a numeric date based on milliseconds and then grap with the time of day- funktion the needed component, here hours (type "help date" and there see "extracting date and time components").

gen double timevar = clock(result_date, "DMYhms")
gen hourvar = hh(timevar)

you might want to keep your new timevar, then bring it with
format timevar %tc
to a more readable format.

hope this helpes you
Marc




Am 28.08.2008 um 12:54 schrieb <Alexander.Severinsen@telenor.com> <Alexander.Severinsen@telenor.com>:


Dear Statalister,

I use Stata 10. I have a string variable, result_date, that records day, month, year, hours, minutes, seconds. It displays, 11.02.2008 08:21:00.000

I would like to generate a new variable that only indicates hours. I had a look at the ntimeofday, written by Nicholas J. Cox (findit ntimeofday), and issed the following command,

ntimeofday result_date, gen(ndatetime) s(dmy h mi s) n(h)

It runs ok, but listing some of these values gives me

list ndatetime in 1/2
| ndatetime |
|-----------|
1. | 421760.35 |
2. | 421759.92 |

I am not sure whether I am on the right track, and maybe all I am missing is to translate these numbers into hours? Any help would be greatly appreciated.

Best wishes,
Alexander Severinsen

*
* 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/
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index