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
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: Generating a new date variable from another date variable
Date
Sat, 2 Mar 2013 16:14:24 +0000
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/