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: Generating a new date variable from another date variable
From
Pinaki Mitra <[email protected]>
To
[email protected]
Subject
Re: st: Generating a new date variable from another date variable
Date
Sat, 2 Mar 2013 14:37:12 -0500
I need to be able to keep all observations. All I need to do is to
assign "Saturday" for variable weekend for all observations in any
given week. So, for the 1st week of 2006, observations for DailyDate
with values 01/01/06, 01/02/06, 01/03/06, 01/04/06, 01/05/06,
01/06/06, 01/07/06 will have a value of 01/07/06 (which is Satusday)
for the variable weekend. It will look like:
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
01/07/2006 01/07/2006
I am not sure how to do this with dow() function.
On Sat, Mar 2, 2013 at 11:14 AM, Nick Cox <[email protected]> wrote:
> There is no need for any kind of loop here. Use the -dow()- function and
> check for the days of the week you do or don't want.
>
> Nick
>
>
> On 2 Mar 2013, at 15:14, Pinaki Mitra <[email protected]> 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/
*
* 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/