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, statalist.org is already up and running.


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

Re: st: date conversion


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: date conversion
Date   Fri, 27 May 2011 09:34:59 +0100

You need to get in the habit of using the help to sort out well
documented issues like these.

1. -tsset- requires numeric variables. If you tried to -tsset- with a
string variable, that won't work and you will have received an error
message to that effect.

2. -encode- just maps string variables to integers 1 up and as you say
throws away the specific date information except insofar as it is
recorded in value labels.

3. Conversion of dates in string form can be achieved using the
-date()- function; see -help dates_and_times-.  Your example is
ambiguous as between MDY and DMY, but one of

gen ndate = date(date, "MDY")

and

gen ndate = date(date, "DMY")

will be the answer in Stata 11. (In Stata 10, and earlier, arguments
would "mdy" or "dmy". )

Nick

On Fri, May 27, 2011 at 4:40 AM, Muhammad Anees <aneesmkhattak@gmail.com> wrote:
> Sorry to post might be not in the right place but my question somehow
> related to the conversion of dates too. 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. Also how can I expect to
> have to have both date and day side by side and no ordering to occure
> when I convert date to day or otherwise.
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index