Have you ever wished that when you referred to the lag of a trading date, you got the previous trading date rather than yesterday? Or if you referred to the lead of a trading date, you got the next trading date and not tomorrow?
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’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.
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 date gaps in the dataset. For instance, if there are no observations for Sundays, Stata infers that Sunday is not a business day. You can also edit the business calendar file created to further specify which dates should or should not be part of the calendar.
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,
To learn more about business calendars, see [D] bcal.
Explore more time-series features in Stata.