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]

st: Generating a new date variable from another date variable


From   Pinaki Mitra <[email protected]>
To   [email protected]
Subject   st: Generating a new date variable from another date variable
Date   Sat, 2 Mar 2013 10:14:58 -0500

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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index