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 at the end of May, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: creating a custom monthly date

From   Eric Booth <>
Subject   Re: st: creating a custom monthly date
Date   Sat, 21 Apr 2012 08:46:40 -0500


Sounds like it could be a job for -help bcal-.
I'm not sure that I fully understand your decision rules for creating the custom month, but this might get you started without -bcal-:

set obs 10000
g date = 15000+runiform()*800 //fake dates
format date %td
duplicates report

gen month = month(date)

clonevar month_new = month
replace month_new = month-1 if  ///
	month(date-2)<month(date) | month(date-1)<month(date) & inrange(dow(date-2), 1, 5)
replace month_new = month+1 if  ///
	month(date+3)>month(date) | month(date+2)>month(date) | month(date+1)>month(date)
g flag = month_new!=month
l if day(date)<2 & flag //check

- Eric

Eric A. Booth
Public Policy Research Institute
Texas A&M University
Office: +979.845.6754

On Apr 21, 2012, at 7:56 AM, Francesco wrote:

> Dear Statalist,
> I have a little problem about the creation a custom date in Stata 12.
> Let me specify what I would like to do : I have a panel dataset with
> daily observations (which may contains multiple identical dates for
> the same id)
> I already know how to obtain the relevant month for each daily date,
> by typing -gen month=mofd(daily_date).
> However, please do not ask me why, I absolutely need to create a
> "custom" month variable that starts 2 days before the end of the
> previous month (in terms of working days) and ends 3 days before the
> start of the next month... I need a way to do that which I can
> reproduce accross different datasets, thus obtaining the same custom
> dates (for a merging purpose)...
> What do you think?
> Could you help me ?
> Many thanks
> *
> *   For searches and help try:
> *
> *
> *

*   For searches and help try:

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