Statalist


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

RE: st: Sort on time


From   "Steichen, Thomas J." <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: Sort on time
Date   Wed, 12 Nov 2008 08:55:43 -0500

This is an instance where "automatic promotion" of the variable to double by Stata would be useful. I have made this mistake enough times that one would think I'd never do it again (but I do...). Svend tripped over it too and I suspect many others have done so also.

So, an open question to StataCorp: Is this blithely proposed "automatic promotion" process possible and, if so, is this an appropriate application of it?

-----------------------------------
Thomas J. Steichen
[email protected]
-----------------------------------

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Steichen, Thomas J.
Sent: Wednesday, November 12, 2008 8:44 AM
To: '[email protected]'
Subject: RE: st: Sort on time

Yes.

Because datetime was not generated as a double.


-----------------------------------
Thomas J. Steichen
[email protected]
-----------------------------------

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Paul McCabe
Sent: Wednesday, November 12, 2008 7:27 AM
To: [email protected]
Subject: Re: st: Sort on time

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/

CONFIDENTIALITY  NOTE:  This e-mail message, including any attachment(s), contains information that may be confidential, protected by the attorney-client or other legal privileges, and/or proprietary non-public information. If you are not an intended recipient of this message or an authorized assistant to an intended recipient, please notify the sender by replying to this message and then delete it from your system. Use, dissemination, distribution, or reproduction of this message and/or any of its attachments (if any) by unintended recipients is not authorized and may be unlawful.

*
*   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/

CONFIDENTIALITY  NOTE:  This e-mail message, including any attachment(s), contains information that may be confidential, protected by the attorney-client or other legal privileges, and/or proprietary non-public information. If you are not an intended recipient of this message or an authorized assistant to an intended recipient, please notify the sender by replying to this message and then delete it from your system. Use, dissemination, distribution, or reproduction of this message and/or any of its attachments (if any) by unintended recipients is not authorized and may be unlawful.

*
*   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