Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Sort on time


From   "Paul McCabe" <[email protected]>
To   [email protected]
Subject   Re: st: Sort on time
Date   Wed, 12 Nov 2008 12:27:29 +0000

Can anyone explain why the time has been changed - 19:10:00 to
19:08:55 - in Svend's example, and how to correct this where
necessary?

Many thanks
Paul

>
> To make the date and time sortable, combine the two strings into
> one, and next transform the string into a numeric date-and time
> (tc) variable. (It has the numeric value of the number of
> milliseconds (!) since 1 January 1960):
>
>    . clear
>    . set obs 1
>    . gen str sdate = "12112008"
>    . gen str stime = "19:10:00"
>    . gen sdatetime = sdate + " " + stime
>    . gen datetime = clock(sdatetime,"DMY hms")
>    . format datetime %tc
>    . list, clean
>              sdate      stime           sdatetime             datetime
>      1.   12112008   19:10:00   12112008 19:10:00   12nov2008 19:08:55
>
> Hope this helps
> Svend
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index