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


From   Nilay Kumar <[email protected]>
To   [email protected]
Subject   Re: st: RE: converting string to date
Date   Fri, 29 Nov 2013 13:26:09 -0500

Hi Joe,

Thanks a lot for your response. Works perfectly. 
I’m new to using Stata and had been getting frustrated over this. This was very helpful.

Nilay
On Nov 29, 2013, at 12:37 PM, Joe Canner <[email protected]> wrote:

> Nilay,
> 
> You should be able to convert each individual date in the string:
> 
> . date1=date(substr(var,1,10),"YMD")
> . date2=date(substr(var,14,10),"YMD")
> 
> If you want a single date out of this, you could pick one of the dates in the week (date1, date2, or something in between) and use the -week()- function to convert it to a week.
> 
> Regards,
> Joe Canner
> Johns Hopkins University School of Medicine
> ________________________________________
> From: [email protected] [[email protected]] on behalf of Nilay Kumar [[email protected]]
> Sent: Friday, November 29, 2013 12:15 PM
> To: [email protected]
> Subject: st: converting string to date
> 
> 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/
> 
> *
> *   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/


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