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: converting string to date


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: converting string to date
Date   Fri, 29 Nov 2013 17:51:34 +0000

My mistake: I missed the bit about weeks. Joe Canner has very good
advice in his reply.

Weeks in my view are best handled by treating them as daily dates 7 days apart.

See also, if you have a serious interest in weeks,

SJ-12-4 dm0065_1  . . . . . Stata tip 111: More on working with weeks, erratum
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q4/12   SJ 12(4):765                                     (no commands)
        lists previously omitted key reference

SJ-12-3 dm0065  . . . . . . . . . .  Stata tip 111: More on  working with weeks
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q3/12   SJ 12(3):565--569                                (no commands)
        discusses how to convert data presented in yearly and weekly
        form to daily dates and how to aggregate such data to months
        or longer intervals

SJ-10-4 dm0052  . . . . . . . . . . . . . . . . Stata tip 68: Week assumptions
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q4/10   SJ 10(4):682--685                                (no commands)
        tip on Stata's solution for weeks and on how to set up
        your own alternatives given different definitions of the
        week

I'm still proud of the weak "week" pun behind "week assumptions". .



Nick
[email protected]


On 29 November 2013 17:47, Nick Cox <[email protected]> wrote:
> This works fine:
>
> . di %td date("2004-01-04", "YMD")
> 04jan2004
>
> Note the very simple -- but  from many posts on this list seemingly
> little known -- technique of trying out a simple example using the
> -display- command and a format that checks whether I get the right
> answer.
>
> But your approach also works fine in the examples I tried
>
> . di %td date("2004-01-04", "20YMD")
> 04jan2004
> . di %td date("1998-01-04", "20YMD")
> 04jan1998
>
> so why did you say "does not seem to work"? Did you forget to assign a
> date format so that what you see is human-readable?
>
>
> Nick
> [email protected]
>
>
> On 29 November 2013 17:15, Nilay Kumar <[email protected]> wrote:
>> I have a dataset where weeks are listed as strings ie. 2004-01-04 - 2004-01-10. How can I convert this entire string to dates?
>> I tried gen date1= date(var, “20YMD”) but that does not seem to work for this

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index