Hugh,
you have two variables date (which shows the date and has 00:00 as
time) and time (which is always Jan1,1960 and proper time). Sorting
first by this variable date, and then by variable time:
sort date time
will have the same effect as if you combined and reformatted the
variables as others suggested.
Regards, Sergiy
On Tue, Nov 11, 2008 at 1:30 PM, Svend Juul <[email protected]> wrote:
> Hugh wrote:
>
> I have 3 variables; id, date, time.
> "date" and "time" both have a storage type of str8 and are both in %9s
> display format. I need to sort on "id", "date" and "time" in that
> sequence.
>
> I am able to get "date" as float %td, but I am having a problem with
> "time". I got "time" as a double %tc, but it obviously comes out with
> the date "01jan1960" plus the time. I have over 2 million
> observations. I am using Stata 10.
>
> ==========================================================
>
> 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
>
> ________________________________________________________
>
> Svend Juul
> Institut for Folkesundhed, Afdeling for Epidemiologi
> (Institute of Public Health, Department of Epidemiology)
> Vennelyst Boulevard 6
> DK-8000 Aarhus C, Denmark
> Phone, work: +45 8942 6090
> Phone, home: +45 8693 7796
> Fax: +45 8613 1580
> E-mail: [email protected]
> _________________________________________________________
>
> *
> * 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/