Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: date conversion


From   Maarten Buis <[email protected]>
To   [email protected]
Subject   Re: st: date conversion
Date   Fri, 27 May 2011 10:03:41 +0200

On Fri, May 27, 2011 at 5:40 AM, Muhammad Anees wrote:
> I have date in the format
> 1/1/2008 and it is in the string format. When I tsset my data using
> the string variable it is not working as usual. Now I have encoded my
> date variable using encode date, gen(day) which generates new day
> variables but when I explore the data all the day variable has been
> re-ordered and what reasons works behind it.

-encode- is not intended to work with dates. It just sorts a string on
alphabetical order and gives the first string a 1, the second a 2,
etc. Since we would like to sort a date on year, month, day, and your
string is day, month, year, the sorting will be completely off.
Moreover, even if the sorting wasn't off, this still would not work,
as this would suggest that each occurrence of a string is one day
apart from the previous occurrence.

For transforming strings to dates, see -help dates-.

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany


http://www.maartenbuis.nl
--------------------------
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index