Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[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 <>
To   "" <>
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.


On 2 Mar 2013, at 15:14, Pinaki Mitra <> wrote:

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.
Pinaki Mitra
*   For searches and help try:
*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index