Thanks for clarifying that for me. I got what a asked for, but I guess I did not ask the correct question. I had a date (string) like 11.02.2008 08:21:00.000, and wanted a new variable with only the time recorded, 08:21. I am looking at offer response (from telemarketing), and in this particular case the actual date is of no interest.
After posting, I solved the problem using 'substr', not sure if that is the most efficient way, but,
gen time=substr(result_date,12,13)
list time in 1/2
+--------------+
| time |
|--------------|
1. | 08:21:00.000 |
2. | 07:55:00.000 |
+--------------+
gave me what I wanted.
Best wishes,
Alex
-----Opprinnelig melding-----
Fra: [email protected] [mailto:[email protected]] P� vegne av Nick Cox
Sendt: 28. august 2008 13:51
Til: [email protected]
Emne: st: RE: Time of day
I tried hard to forget the minor agonies of writing -?timeofday- once StataCorp had done the job properly in Stata 10.
But times in hours from -ntimeofday- are (as with all Stata date-times) measured relative to 1 January 1960. Some simple calculations show that hours above about 400000 are what you should get for recent dates. For example, today's date gives
. di 24 * mdy(8,28,2008)
426528
So, my impression is that you got what you asked for, i.e. the result _is_ in hours.
I wrote the -?timeofday- stuff because (a) some colleagues needed it (b) StataCorp did not seem inclined to do it. (b) was promptly reversed, but a consequence of (a) is that I have not used the official time of day stuff myself in Stata 10. But I would be surprised if you cannot get what you want using official commands.
Nick
[email protected]
Alexander.Severinsen
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.
*
* 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/