|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: dates in stata
Your date is entered as a string, not a real date format. Real dates
are integer values, representing (currently) the number of days elapsed
since January 1st 1960.
Try this:
> . edit
> (1 var, 13 obs pasted into editor)
>
> . list
>
> +------------------+
> | var1 |
> |------------------|
> 1. | 01 April 2005 |
> 2. | 01 April 2008 |
> 3. | 01 August 2000 |
> 4. | 01 August 2001 |
> 5. | 01 August 2002 |
> |------------------|
> 6. | 01 August 2003 |
> 7. | 01 August 2005 |
> 8. | 01 August 2006 |
> 9. | 01 August 2007 |
> 10. | 01 August 2008 |
> |------------------|
> 11. | 01 December 2000 |
> 12. | 01 December 2003 |
> 13. | 01 December 2004 |
> +------------------+
>
> . gen dateval=date( var1, "DMY")
>
> . list
>
> +----------------------------+
> | var1 dateval |
> |----------------------------|
> 1. | 01 April 2005 16527 |
> 2. | 01 April 2008 17623 |
> 3. | 01 August 2000 14823 |
> 4. | 01 August 2001 15188 |
> 5. | 01 August 2002 15553 |
> |----------------------------|
> 6. | 01 August 2003 15918 |
> 7. | 01 August 2005 16649 |
> 8. | 01 August 2006 17014 |
> 9. | 01 August 2007 17379 |
> 10. | 01 August 2008 17745 |
> |----------------------------|
> 11. | 01 December 2000 14945 |
> 12. | 01 December 2003 16040 |
> 13. | 01 December 2004 16406 |
> +----------------------------+
>
> . format dateval %d
>
> . list
>
> +------------------------------+
> | var1 dateval |
> |------------------------------|
> 1. | 01 April 2005 01apr2005 |
> 2. | 01 April 2008 01apr2008 |
> 3. | 01 August 2000 01aug2000 |
> 4. | 01 August 2001 01aug2001 |
> 5. | 01 August 2002 01aug2002 |
> |------------------------------|
> 6. | 01 August 2003 01aug2003 |
> 7. | 01 August 2005 01aug2005 |
> 8. | 01 August 2006 01aug2006 |
> 9. | 01 August 2007 01aug2007 |
> 10. | 01 August 2008 01aug2008 |
> |------------------------------|
> 11. | 01 December 2000 01dec2000 |
> 12. | 01 December 2003 01dec2003 |
> 13. | 01 December 2004 01dec2004 |
> +------------------------------+
>
> . sort dateval
>
> . list
>
> +------------------------------+
> | var1 dateval |
> |------------------------------|
> 1. | 01 August 2000 01aug2000 |
> 2. | 01 December 2000 01dec2000 |
> 3. | 01 August 2001 01aug2001 |
> 4. | 01 August 2002 01aug2002 |
> 5. | 01 August 2003 01aug2003 |
> |------------------------------|
> 6. | 01 December 2003 01dec2003 |
> 7. | 01 December 2004 01dec2004 |
> 8. | 01 April 2005 01apr2005 |
> 9. | 01 August 2005 01aug2005 |
> 10. | 01 August 2006 01aug2006 |
> |------------------------------|
> 11. | 01 August 2007 01aug2007 |
> 12. | 01 April 2008 01apr2008 |
> 13. | 01 August 2008 01aug2008 |
> +------------------------------+
>
> .
[email protected] wrote:
> 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/