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   Muhammad Anees <[email protected]>
To   [email protected]
Subject   Re: st: date conversion
Date   Fri, 27 May 2011 14:48:03 +0500

Thank Nick and Maarten!

Nick! I have silently read many of your posts and came to the same
conclusion that I should have read help files before taking times of
other experts but you know one misses things unintentionally as I did
in this very basic data manipulation. I am grateful to you always for
your constructive guidance adding always to my knowledge of using
Stata.

I did the following and came with the new date variable which is now a
numeric serries but having missing entries for the missing dates which
I can use equally as my day variable. The resultant and original dates
are now after changing the format of day variable in Excel which I
think can be done in Stata.

. generate date = date(day, "MDY")
. li day date in 1/10

     +---------------------------+
     |               day    date |
     |---------------------------|
  1. | December 31, 2010   18627 |
  2. | December 30, 2010   18626 |
  3. | December 29, 2010   18625 |
  4. | December 28, 2010   18624 |
  5. | December 27, 2010   18623 |
  6. | December 24, 2010   18620 |
  7. | December 23, 2010   18619 |
  8. | December 22, 2010   18618 |
  9. | December 21, 2010   18617 |
 10. | December 20, 2010   18616 |
     +---------------------------+

I have the desired results in further analysis which became possible
after this conversion only. Thank you very much Nick and Maarten and
hope to have your guidance.

Anees



On 27 May 2011 13:34, Nick Cox <[email protected]> wrote:
> 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 <[email protected]> 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/
>



-- 
---
Best,


---------------
Anees

*
*   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