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 12, 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 new 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|
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.
Business dates work just like regular dates; it is just that some dates are crossed out.
Explore more time-series capabilities in Stata.
For a complete list of what’s new in time-series analysis, click here.
See New in Stata 13 for more about what was added in Stata 13.