Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Joe Canner <jcanner1@jhmi.edu> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | st: RE: converting string to date |
Date | Fri, 29 Nov 2013 17:37:05 +0000 |
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: owner-statalist@hsphsun2.harvard.edu [owner-statalist@hsphsun2.harvard.edu] on behalf of Nilay Kumar [nilaykumar83@gmail.com] Sent: Friday, November 29, 2013 12:15 PM To: statalist@hsphsun2.harvard.edu 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/