Hi Statalist,
I added an exchange between Paul and me.
I am using version 9.1
I tried all your suggestions, but nothing worked...
Maybe someone eöse can help me?
Zitat von "E. Paul Wileyto" <[email protected]>:
May I ask what version of Stata you are using? My version is 10. This
date conversion goes back to previous versions, but I cannot swear
about 7 or 8, and I cannot swear that older versions will take dates
written like that, with the spaces, and the whole month written out.
I'm going to suggest something off the wall, but can you try...
gen dateval=date( event_date, "D M Y")
with spaces in the DMY?
Also try
gen dateval=date( event_date, "DM20Y")
gen dateval=date( event_date, "D M 20Y")
Just a hunch.
P
[email protected] wrote:
Hi Paul,
this is what I got. So I guess it is a string???
. des event_date
storage display value
variable name type format label variable label
-------------------------------------------------------------------------------
event_date str17 %17s
Zitat von "E. Paul Wileyto" <[email protected]>:
Dots are missing values. Everyone has been assuming you have dates in
strings. Could you check this. Type -des event_date
Then look at the format returned. If it is a string, is will give you
something like %20s. If it doesn't have that "s" in the format, it
is not a string, and I'll be scratching my head.
P
[email protected] wrote:
Hi Paul,
thank you very much for your answer. I tried to follow your suggestions.
I don't know what I did wrong, but I just got some dots (see below).
Can you tell me what I am doing wrong?
Best Regards Lisa
. gen dateval=date( event_date, "DMY")
(84 missing values generated)
. list
+----------------------------------------------+
| company_id event_date dateval |
|----------------------------------------------|
1. | Nintendo 09 May 2006 . |
2. | Palm 18 May 2005 . |
3. | Apple 23 October 2001 . |
4. | Apple 07 September 2005 . |
5. | Apple 11 January 2005 . |
|----------------------------------------------|
6. | Apple 06 January 2004 . |
7. | Apple 05 September 2007 . |
8. | Apple 09 January 2007 . |
9. | Apple 07 August 2007 . |
10. | Apple 01 May 2001 . |
|----------------------------------------------|
11. | Apple 15 January 2008 . |
12. | Apple 14 October 2008 . |
13. | LG 11 December 2006 . |
14. | LG 11 February 2008 . |
15. | Pioneer 07 January 2008 . |
|----------------------------------------------|
Zitat von "E. Paul Wileyto" <[email protected]>:
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/