Search
   >> Home >> Products >> Features >> Overview >> Business calendars

Business dates and calendars

Have you ever wished that when you referred to the lag of trading date, you got the previous trading date rather than yesterday’s? Or if you referred to the lead of trading date, you got the next trading date and not tomorrow’s?

In Stata, L.trading_date can mean the previous trading date and F.trading_date can mean the next trading date. All you have to do is create the business calendar that describes your dates.

Stata provides lots of built-in date and time formats. It has dates and times (millisecond accuracy, leap-second adjusted or not), dates, weeks, months, quarter, half-years, and years. Now, joining those are user-defined business dates.

Stata’s built-in dates are known technically as %tc and %tC (datetimes), %td (regular dates), %tw (weekly dates), %tm (monthly dates), %tq (quarterly dates), %th (half-yearly dates), and %ty (yearly dates). Stata has all those built-in formats to make lag and lead operators operate as you would expect them to work, and to make data management easy.

The business dates format is known technically as %tb.

A business calendar is like an ordinary calendar with some dates crossed out. The crossed-out dates correspond to the dates on which the “business” is closed:

Business closed on crossed-out dates
November 2011
Su MTuWe T F Sa
1 2 3 4 X
X 7 8 9 10 11 X
X 14 15 16 17 18 19
X 21 22 23 X 25 X
X 28 29 30 

With a business date, yesterday is the last day the business was open, and tomorrow is the next day the business will be open.

Consider date = 25nov2011.

Then, if date is a regular %td date variable,

                 yesterday = date - 1 = 24nov2011      

                  tomorrow = date + 1 = 26nov2011      

If date is a %tb date variable,

                 yesterday = date - 1 = 23nov2011      

                  tomorrow = date + 1 = 28nov2011      

If variable trading_date is a regular %td variable, then L.trading_date really is yesterday and F.trading_date really is tomorrow. But if trading_date has an appropriately defined %tb format, L.trading_date is the previous trading date and F.trading_date is the next trading date.

To make a business calendar, you create a file named calname.stbcal, such as nyse.stbcal. After that, Stata deeply understands the new format %tbnyse.

Making a business calendar is easier than ever. You can now load a dataset into memory and have Stata automatically determine which days should appear on the calendar based on which observations contain missing values. You can also create a file that tells Stata which dates should or should not be part of the calendar.

bcal create makes it easy to create a business calendar. For instance,

. sysuse sp500 (S&P 500) . bcal create sp500, from(date) Business calendar sp500 (format %tbsp500): purpose: range: 02jan2001 31dec2001 14977 15340 in %td units 0 247 in %tbsp500 units center: 02jan2001 14977 in %td units 0 in %tbsp500 units omitted: 116 days 116.4 approx. days/year included: 248 days 248.9 approx. days/year REMARKS: business calendar file sp500.stbcal saved

Explore more time-series features in Stata.

The Stata Blog: Not Elsewhere Classified Find us on Facebook Follow us on Twitter LinkedIn Google+ Watch us on YouTube