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]

Re: st: creating a custom monthly date


From   Eric Booth <[email protected]>
To   [email protected]
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-:

*******************!
clear
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
[email protected]
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:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/


*
*   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