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: RE: Categorising dates


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: Categorising dates
Date   Tue, 24 Aug 2010 15:33:40 +0100

To get any distance in working with dates, you need to study the menagerie of associated functions. Start at -help dates-. 

The second question, which looks simpler, is ambiguous. Do you mean just month, so that 

Month of 24 August 2010 := August 

-- or do you really mean year and month, so that 

Month of 24 August 2010 := August 2010 

? 

For the first, use -month()-. For the second use, -mofd()-. Examples:

. di month(mdy(8,24,2010))
8

. di mofd(mdy(8,24,2010))
607

. di %tmm_Cy  mofd(mdy(8,24,2010))
Aug 2010

The second question looks less simple but is clear. Stata has a -dow()- function yielding day of the week, coded 0 for Mondays through 6 for Saturdays. Therefore the previous Monday is given by 

gen mondays = cond(dow(day) == 0, day - 6, day - dow(day) + 1)

i.e. 6 days before any Sunday, etc. 

This variable codes days by the previous Monday, and so classifies weeks accordingly. 
There may well be a simpler way to do it. 

Nick 
[email protected] 

sara khan

I have a list of daily dates inthe format, for example, 23 Sep 09, and
need to create two variables. One is to categorise the days into
weekly data (so week commencing on a Monday). The second is to create
a variable cataegorsing the daily data into monthly data.

I would be grateful for advice on how to do this.


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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