Time Series Analysis/ Datetime Business Calendars

#1
Hi all,

I am doing a time-series analysis of the S&P500, and I have imported all of my variables in from excel. I am having trouble converting the date variable from excel into business calendar form while still retaining the accurate dates.
Thus far, I have performed the commands (as per STATA's link http://www.stata.com/bookstore/stata12/pdf/d_datetime_business_calendars.pdf ):

generate _date = date(date, "MDY")
format _date %td
drop date
generate mydate = bofd("simple", _date)
format mydate %tbsimple

When I say "list mydate", however, all the values show as "."

I also emailed STATA tech support, but there seems like an easier way to complete my goals. Their recommendations included opening the do-file editor, entering

version 12
dateformat dmy
range 20jul2007 19jul2012
centerdate 20jul2007
omit dayofweek (Sa Su)
omit date 1jan*
omit dowinmonth +2 Mo of jan

saving this to the PERSONAL directory, reopening the do-file editor, and running this final program:

clear all
set obs 362
generate day=mdy(01,04,2010)+_n-1
format day %td
generate mydate = bofd("mybcal",day)
format mydate %tbmybcal
list in 1/30
bcal de mybcal
tsset mydate
generate x=int(uniform()*20)
generate lx=l.x
list in 1/30

.. But this didn't seem to work (or I could not figure it out). Any thoughts?

I am relatively inexperienced when it comes to STATA, and even more inexperienced when it comes to time-series analysis, so any help is greatly appreciated.

Thanks for any insight!
R
 
#2
For date calculation, it has to be stored as numeric, for example, in Stata's %td format, 01Jan1960 is 1, 02Jan1960 is 2,....
since we know the number before 2 is 1, so we know one lag of 02Jan1960 is 01Jan1960.

Using business calender, you could define your own origin, and omit weekends for example.
If you use the defined business calender, using 15Aug2012 as origin and omit weekends,
then 0 -> 15Aug2012, 1->16Aug2012, 2->17Aug2012, but 3-> 20Aug2012 (skip weekends 18 and 19).
Now based on this calender, one lag of 20Aug2012 is no long 19Aug2012 but 17Aug2012.

So the reply from Stata technical service tells you to define a business calendar first, like

version 12
dateformat dmy
range 20jul2007 19jul2012
centerdate 20jul2007
omit dayofweek (Sa Su)
omit date 1jan*
omit dowinmonth +2 Mo of jan

save it as mybcal.stbcal file. And later when you run your code, you could use this calender, as in

generate mydate = bofd("mybcal",day)

the definition of your calender applies.