Option window()


The latest version of asrol accepts up to three arguments and is written in like this:

window(rangevar #from #up to)

The rangevar is usually a time variable such as date, monthly date, or yearly date. Both #from and #upto are numeric values that mark how far the window will go away from the current value of the rangevar. Negative values of these mean going back # periods from the current observation. Similarly, positive values mean going ahead # periods from the current observations. asrol considers the focal observation as part of the past. In the following paragraphs, I present some examples to understand option window() more clearly.

Example 1: Last 5 years, including the most recent one

If we were to estimate the mean of the last 5 years, given that we have a total of 5 observations and years are 2001, 2002, 2003, 2004, and 2005. For the year 2005, the window will count years [2001, 2002, 2003, 2004, and 2005] as the past 5 years. The window argument of asrol will be written like this:

window(year -5 0)

The third argument of the window() option is 0 (zero), which means include observations up to the current one.

Example 2: Back window of 5 periods and exclude the most recent one

If we were to estimate a rolling window of 5-years but want to exclude the most recent observation, then the window argument will be written as:

 window(year -5 -1)

Using the earlier example, the window will restrict calculations to these years [2001, 2002, 2003, 2004], i.e. it will exclude the focal year, which is 2005. Therefore, there will be only 4 observations in the calculations of the mean value.

Example 3: Back window of 5-periods and one-year forward 

In this case, the window option will be written as:

window(year -5 1)

Example 4: Window definition based on t-number  to t-another number

The above interpretation of the option window might be confusing when implementing a definition that is based on t-# up to t-#2. However,  the following example should clarify such confusion, if any. Consider a stock momentum strategy that asks for cumulative returns over the previous 11 months from month t-12 up to t-2. Let’s say that we estimate this cumulative return at the end of December 2019. This strategy will include the following months in the calculations which are given in the square  brackets and exclude the ones that are outside the brackets :

[Dec-18, Jan-19, Feb-19, Mar-19, Apr-19, May-19, Jun-19, Jul-19, Aug-19, 
Sep-19, Oct-19], Nov-19, Dec-19.

From Dec-18 up to Dec-19, there are 13 months. To implement this using asrol, the window argument will be written as:

window(year -13 -2)

Example 5: Window of +5 to +10

This window shall include observations that are away 5-periods into the future from the current observation up to 10-periods into the future. Therefore, if the current observation is the year 2000, the window shall include the following years

[2006, 2007, 2008, 2009, 2010].

The option window() will be typed as

window(year 5 10)

Example 6: Window of 0 to +9 or -1 to +9

See this Statalist post for more details on this example. This window shall include current observation and other observations that are away 9-periods into the future from the current observation . Therefore, if the current date is Oct 1st, the window shall include the following dates:

[Oct1, Oct2, Oct3, Oct4, Oct5, Oct6, Oct7, Oct8, Oct9, Oct10].

The option window() will be typed as

window(date 0 9)
OR
window(date -1 9)

Why both the options yield same results?
The reason is that asrol considers the current observation as part of the history, i.e. this data has already occurred and is now part of the history, therefore observation 0 and -1 means the same thing.