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:47:13 +0000
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/