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 Stata 12 business calendar


From   Alberto Dorantes <[email protected]>
To   [email protected]
Subject   Re: st: creating a Stata 12 business calendar
Date   Tue, 24 Apr 2012 17:13:30 -0500

Another very simple solution is creating a time consecutive variable
in your dataset with the command, and tsset with this variable:
gen myt=_n
tsset myt

The disadvantage of doing this is that if you use graphs or most
output commands,  you will see this number myt, not the actual date in
a "human readable" format.

Regards... Alberto.


2012/4/24 Alberto Dorantes <[email protected]>:
> Hi Francesco.
> Here is an example that might help you:
>
> 1) Create a time series stata file with all possible business days in
> the period you want
> 2) Using tsset and tsfill create a file that has the days that are
> omitted in your time series, and save this file
> 3) Edit this file in the format required by any
> Stata-Business-Calendar file (.stbcal) to indicate the time period and
> other details.
> 4) Save this file with the extension .stbcal
> 5) Use the function bofd to calculate your own calendar code
> 6) format your calendar code variable using %tbYOURVARIABLE
>
> Here is an example:
>
> * Using the s&p500 index from the online Fred database:
> freduse SP500
> * If you have not used the freduse command, just type "findit
> freduse", and install this command
> tsset daten
> * Use the tsfill command to add ALL possible dates that are not
> included in the SP500 file:
> tsfill
> * Now keep only those dates that were included with the tsfill command
> (the omitted dates or non-business days):
> keep if SP500==.
> drop date SP500
> * Now drop all weekend days from the file:
> drop if dow(daten)==0 | dow(daten)==6
> * Now generate 2 string variables:
> gen omit="omit "
> gen date="date "
> * Change the order of the variables:
> order daten, after(date)
> * Now save the file to a txt file with the extension .stbcal:
> outsheet using "micalendario.stbcal", comma nonames replace
>
> /* The following are instructions you HAVE to FOLLOW to MANIPULATE the
> .stbcal file:
>
> * Open the Stata do-file Editor, and load the file micalendario.stbcal
> and replace the double quote (") character by an empty
> * character, and the comma character by an empty space.
> * At the beginning of the file, copy the following rows to the file
> (without the asterisc *):
> * version 12
> * range 02jan1957 23apr2012
> * centerdate 01jan1960
> * omit dayofweek (Sa Su)
> *
> * Save the file with the same name "micalendario.stbcal" or the name
> you had chosen
> */
>
> * Now you can continue with the following commands to generate your
> business calendar code:
>
> freduse SP500, clear
> gen diahabil=bofd("micalendario", daten)
> format diahabil %tbmicalendario
> * Testing that your calendar code worked, type:
> tsset diahabil
> count if missing(L1.SP500) & _n>1
> * You have to get zero from this count. This means that in your
> calendar code, there are no gaps, so you can use tsset without
> *  problem.
> * THAT'S IT!
>
> The micalendario.stbcal file have to look something like:
>
> version 12
> range 02jan1957 23apr2012
> centerdate 01jan1960
> omit dayofweek (Sa Su)
>
> omit date 22feb1957
> omit date 19apr1957
> omit date 30may1957
> omit date 04jul1957
> omit date 02sep1957
> omit date 05nov1957
> omit date 28nov1957
> omit date 25dec1957
> omit date 01jan1958
> omit date 04apr1958
> omit date 30may1958
> omit date 04jul1958
> omit date 01sep1958
> omit date 04nov1958
> omit date 27nov1958
> omit date 25dec1958
> omit date 26dec1958
> ...
> ...
>
> I hope this will help.
>
> Alberto Dorantes.
>
>
> 2012/4/22 Francesco <[email protected]>:
>> Dear Statalist,
>>
>> I would like to create my own business calendar, but I cannot find how
>> by just reading the manual...
>> It seems indeed that when creating a .stbcal file I can only omit
>> specific dates (holidays, sundays, etc).
>>
>> However I would like to do the opposite : I directly have the full
>> list of business dates I would like to consider.. I am doing this
>> because I would like to easily obtain the previous  business day from
>> any date in my dataset (according to my calendar)
>> How can I tell Stata 12 to use those dates as a new business calendar
>> ? Do you have an idea ?
>>
>>
>> Many thanks for your suggestions,
>> Best
>> *
>> *   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