Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: Week of the month


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: Week of the month
Date   Sun, 7 May 2006 16:24:27 +0100

The week of each day is given by 

gen week = week(date) 

The first trading day of each month is given by 

gen first = mdy(month(date), 1, year(date)) 

except that we must adjust Saturdays and Sundays: 

replace first = cond(dofw(first) == 0, first + 1, cond(dow(first) == 6, first + 2, first))

So week in month would be 

replace week = week - week(first) + 1 

Nick 
n.j.cox@durham.ac.uk 

Rajesh Tharyan
 
> This may help
> 
> help dcfcns
 
Katrin Gottschalk
 
> does anybody know of an easy way to obtain the NUMERIC WEEK 
> OF THE MONTH
> (i.e. 1,...,5) corresponding to an elapsed date? Should be something
> similar to date functions day(e), dow(e), doy(e), week(e)...
> I have a panel data set with daily observations. Week No. 1 should be
> defined as the first week of the month that contains at least one
> trading day (Mon - Fri).

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index