Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

Re: st: date conversion

From   Maarten Buis <>
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 L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index