Examples / AKAIKE.RPF |
AKAIKE.RPF is an example of the use of information criteria for choosing lag length. It also demonstrates how to use the REPORT instruction to generate a user-defined table. This is the same model used in DISTRIBLAG.RPF.
This allows for lags from 0 to as many as 24. It uses CMOMENT and LINREG(CMOM) to ensure that all the regressions are run over the same set of entries. (If you just do separate LINREG's, the estimates on shorter lags will be able to use extra data points since fewer observations are lost to the lags, and would do that unless you control the range).
Given the CMOMENT instruction (which includes all the possible explanatory variables plus the dependent variable LONGRATE):
cmom
# constant shortrate{0 to 24} longrate
a regression using just LAG lags can be done with
linreg(cmom,noprint) longrate
# constant shortrate{0 to lag}
The program does a loop over the possible lag lengths (0 to 24) two times. The first uses DISPLAY instructions (with the @ tags to put information at specific positions on the line) to show the Akaike and Schwarz criteria, which are computed from the LINREG variables %LOGL, %NREG and %NOBS.
disp "Lag" @10 "Akaike" @20 "Schwarz"
do lag=0,24
linreg(cmom,noprint) longrate
# constant shortrate{0 to lag}
compute akaike =(-2.0*%logl+%nreg*2.0)
compute schwarz=(-2.0*%logl+%nreg*log(%nobs))
disp lag ##.### @10 akaike @20 schwarz
end do
You would be looking for the smallest value in each column.
The second loop does the same calculations, but uses REPORT to construct a table with the information, and uses the @REGCRITS procedure to compute the criteria, showing in the REPORT the %AIC and %SBC variables defined by the procedure.
report(action=define,hlabels=||"Lags","Akaike","Schwarz"||,$
title="Distributed Lag IC")
do lag=0,24
linreg(cmom,noprint) longrate
# constant shortrate{0 to lag}
@regcrits(noprint)
report(row=new,atcol=1) lag %aic %sbc
end do
That creates the table, but does not show it. Before it does that, this "tags" with a star the minimum value in each of the columns, and formats the numbers with decimal alignment with three digits right of the decimal:
report(action=format,tag=minimum,special=onestar,atcol=2,tocol=2)
report(action=format,tag=minimum,special=onestar,atcol=3,tocol=3)
*
report(action=format,picture="*.###",align=decimal)
report(action=show)
@REGCRITS uses versions of the criteria that are scaled by the number of observations, which is why the values are quite a bit different. However, the order is unchanged by that.
Full Program
open data haversample.rat
calendar(m) 1947
data(format=rats) 1947:1 2007:4 fltg ftb3
set shortrate = ftb3
set longrate = fltg
*
cmom
# constant shortrate{0 to 24} longrate
*
* Using DISPLAY instructions
*
disp "Lag" @10 "Akaike" @20 "Schwarz"
do lag=0,24
linreg(cmom,noprint) longrate
# constant shortrate{0 to lag}
compute akaike =(-2.0*%logl+%nreg*2.0)
compute schwarz=(-2.0*%logl+%nreg*log(%nobs))
disp lag ##.### @10 akaike @20 schwarz
end do
*
* Using REPORT
*
report(action=define,hlabels=||"Lags","Akaike","Schwarz"||,$
title="Distributed Lag IC")
do lag=0,24
linreg(cmom,noprint) longrate
# constant shortrate{0 to lag}
@regcrits(noprint)
report(row=new,atcol=1) lag %aic %sbc
end do
*
* Tag with a * the minimum in the 2nd and in the 3rd columns.
*
report(action=format,tag=minimum,special=onestar,atcol=2,tocol=2)
report(action=format,tag=minimum,special=onestar,atcol=3,tocol=3)
*
* Use a common format of three decimals to the right. Force the numbers
* to align on the decimal point for easy reading.
*
report(action=format,picture="*.###",align=decimal)
report(action=show)
Output
Lag Akaike Schwarz
0 2290.637 2299.740
1 2276.141 2289.795
2 2252.559 2270.763
3 2232.629 2255.385
4 2208.868 2236.174
5 2187.955 2219.813
6 2168.629 2205.038
7 2149.765 2190.724
8 2133.149 2178.660
9 2116.082 2166.143
10 2093.188 2147.801
11 2073.704 2132.868
12 2056.417 2120.132
13 2041.233 2109.499
14 2027.499 2100.317
15 2005.038 2082.406
16 1981.169 2063.088
17 1952.671 2039.141
18 1927.778 2018.799
19 1906.208 2001.781
20 1888.031 1988.154
21 1868.756 1973.430
22 1848.252 1957.478
23 1828.058 1941.835
24 1806.112 1924.440
Lags Akaike Schwarz
0 3.275 3.295
1 3.254 3.280
2 3.221 3.253
3 3.192 3.231
4 3.158 3.204
5 3.129 3.181
6 3.101 3.159
7 3.074 3.139
8 3.050 3.122
9 3.026 3.104
10 2.993 3.078
11 2.965 3.056
12 2.941 3.038
13 2.919 3.023
14 2.899 3.010
15 2.867 2.984
16 2.833 2.957
17 2.792 2.922
18 2.757 2.893
19 2.726 2.869
20 2.700 2.850
21 2.673 2.829
22 2.643 2.806
23 2.614 2.783
24 2.583* 2.759*
Copyright © 2025 Thomas A. Doan