Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Francesco <cariboupad@gmx.fr> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: creating a custom monthly date |
Date | Sat, 21 Apr 2012 15:58:42 +0200 |
Many thanks Eric for your kind suggestion, I will try it right now! Have a nice day, Best On 21 April 2012 15:46, Eric Booth <eric.a.booth@gmail.com> wrote: > <> > > 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 > ebooth@ppri.tamu.edu > 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/ * * 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/