Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <njcoxstata@gmail.com> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | Re: st: Generating a new date variable from another date variable |
Date | Sat, 2 Mar 2013 16:14:24 +0000 |
Nick On 2 Mar 2013, at 15:14, Pinaki Mitra <mitrapin@gmail.com> wrote:
Hello, I have a data variable where each observation is different dates of 2006 to 2012. I need to summarize this data by weekend (each Saturday of each week). I attempted to generate a new date variable (weekend) and collapse the data by weekend. But I am having difficulty in generating the weekend variable from the actual date variable. For example, DailyDate(original variable) WeekendDate (Want to generate) 01/01/2006 01/07/2006 01/03/2006 01/07/2006 01/04/2006 01/07/2006 01/05/2006 01/07/2006 01/06/2006 01/07/2006 I tried: local stdate1:di %dN/D/Y (date("01/01/2006","MDY")) local enddate1:di %dN/D/Y (date("12/31/2012","MDY")) gen WndDate=date("01/01/2006","MDY"); format WndDate %dN/D/Y; while `stdate1'<=`enddate1'{;replace WndDate=`stdate1'+6 if DailyDate>=`stdate1' & DailyDate<=`stdate1'+6;local stdate1=`stdate1'+6; }; It does not work. Would anyone please help? Thank you. Sincerely, Pinaki Mitra * * 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/