Statalist


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

st: Re: dates in stata


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: Re: dates in stata
Date   Tue, 31 Mar 2009 23:28:52 +0200

<>

Lisa may also profit from Nick`s http://www.stata-journal.com/sjpdf.html?articlenum=pr0006

The essential point here is that you read in your dates as strings, and when you fire up -sort- it sorts like you would sort, say, surnames: according to the alphabet.

Once you have applied the string-to-date functions recommended in this thread and described under -help dates_and_times, mark(str2num)-, dates are defined as number of days from 1/1/1960. This allows you to sort a numeric variable, although it is still displayed as 1/8/2008, according to the format you apply to the new variable...

HTH
Martin
_______________________
----- Original Message ----- From: <[email protected]>
To: <[email protected]>
Sent: Tuesday, March 31, 2009 10:44 PM
Subject: st: dates in stata


Hello Statalist,

I am using Stata for event study. I entered all my variables and observations. Regarding my variable "date" I have a problem. When I use "sort date", stata sorts the date shown above:date
01 April 2002
01 April 2003
01 April 2004
01 April 2005
01 April 2008
01 August 2000
01 August 2001
01 August 2002
01 August 2003
01 August 2005
01 August 2006
01 August 2007
01 August 2008
01 December 2000
01 December 2003
01 December 2004
01 December 2005
01 December 2006
01 February 2000
01 February 2001
01 February 2002
01 February 2005
01 February 2006
01 February 2007
01 February 2008
01 July 2002
01 July 2003
01 July 2004
01 July 2005
01 July 2008
01 June 2000
01 June 2001
01 June 2004
01 June 2005
01 June 2006
01 June 2007
01 March 2000
01 March 2001
01 March 2002
01 March 2004
01 March 2005
01 March 2006
01 March 2007
01 May 2000
01 May 2001

I can tell that stata sorts by the first letter of the month. Do I have to use a special format for the date? I also tried the format 01.04.2002, but that gives me the same sortation shown above.

Can anyone help me?

Best regards
Lisa



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