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|
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,
Explore more time-series features in Stata.