Statistics and Algorithms / Forecasting (Introduction) / Saving and Using Forecasts |
Saving Output from UFORECAST and FORECAST
UFORECAST and FORECAST provide tremendous flexibility for handling output. You can:
•save your forecasts directly into series, which you can then print, graph, write to a data file, or use for further analysis.
•use the PRINT option to display the forecasts in the output window.
•use the WINDOW option to display the forecasts in a spreadsheet-style window. This provides convenient viewing of the forecasts, and also allows you to Copy and Paste the forecasts into spreadsheet programs or other applications, or export the data directly to a file with the File—Export operation.
Saving Forecasts in Series
This is straightforward for UFORECAST. For FORECAST, you can save your forecasts into series in three ways:
•If you are using supplementary cards to list the equations (rather than using the MODEL option), you can simply provide series names for the forecasts as the second parameter on each supplementary card. This example forecasts the equation SALESEQ and stores the forecasts in a series called LOGFORE:
forecast(from=1994:1,to=1994:12) 1
# saleseq logfore
• If there are several equations, you don’t have to save forecasts for each of the equations. Just leave off the forecasts parameter on a supplementary card if you don’t need that equation’s forecasts.
•When using the GROUP instruction to create a model, use the “>>series” notation on GROUP to provide the names for the forecast series. When you forecast the model (using the MODEL option), the forecasts will be stored in those series (see the example with GROUP).
•You can use the RESULTS option on FORECAST to save the forecasts in a VECTOR of SERIES.
You can save your forecasts into existing series (including the actual dependent variables), or you can have FORECAST create new series (see “Saving Series in a Loop” for an exception). Note that saving your forecasts back into the dependent variable(s) has no effect on the actual forecasts produced, because the forecasts are computed and stored internally before being saved to the target series.
This example computes forecasts for an interest rate series and stores them in a new series called OLSFORE. The forecasts intentionally overlap the estimation range.
linreg(define=irateeq) rate 1960:1 1995:8
# constant ip grm2 grppi{1}
uforecast(equation=irateeq) olsfore 1995:1 1996:2
And this example forecasts a MODEL, and uses the RESULTS option to save the forecasts in a VECTOR of SERIES called FORECASTS:
forecast(model=gdpmod,results=forecasts,steps=24)
If you would like to use FORECAST inside a loop (or other compiled section, such as a procedure) and want to save the forecasts into new series, you must either use the RESULTS option to store the forecasts, or else create the new series prior to the beginning of the compiled section (using, for instance, DECLARE, SET, or CLEAR).
The WINDOW and PRINT Options
The WINDOW option allows you to display the forecasts in a report window. This provides a convenient way to view the results, and it also allows you to Copy and Paste the data directly into a spreadsheet program or other application, or export the data using the File—Export menu operation. The argument of the WINDOW option provides the title for the output window. For example, the following forecasts twenty-four steps of a six variable model, putting the forecasts into a window named “Forecasts.”
forecast(model=sixvar,window="Forecasts",steps=24)
The PRINT option on FORECAST causes the forecasted values to be displayed in the output window. PRINT also inserts the table into the Report Windows list on the Windows menu so you can reload it. Both PRINT and WINDOW can be used with any of the other methods of saving or displaying output.
forecast(model=gdpmod,results=forecsts,print,steps=24)
Graphing Forecasts
If you save your forecasts into series, you can graph them using the GRAPH or SCATTER instructions. This example forecasts log sales, saves the forecasts in a series called LOGFORE and then graphs both the forecasts and (part of) the original series (LOGRSALES).
uforecast(equation=saleseq) logfore 1994:1 1994:12
graph(key=below,header="Log Trend Model") 2
# logrsales 1993:1 1994:12
# logfore
Saving Forecasts to Files
To save your forecasts to a file, you can either:
•save the forecasts into a series and output the series using COPY, or
•use the WINDOW option to display your forecasts in a window. You can export the data by doing File—Export, or you can use Edit—Copy to copy the data to the clipboard for pasting into another application.
For example, this creates a file named LOGMODELFORE.XLS for the forecasts.
uforecast(equation=saleseq) logfore 1994:1 1994:12
open copy logmodelfore.xls
copy(format=xls,org=cols,dates) / logfore
close copy
Forecasting with Rolling Regressions
Computing forecasts based on a series of rolling regressions (that is, a series of regressions performed over changing sample periods) is a common practice, and an easy one to implement in RATS.
Here, we first run the regression through 1991:12, and compute a forecast for 1992:1. Then we estimate through 1992:1 and forecast 1992:2, and so on. Note that we have used the NOPRINT option on LINREG. We really aren’t interested in seeing 36 regressions—we want the forecasts.
clear rhat
do regend=1991:12,1994:11
linreg(noprint) logrsales * regend
# constant time logrsales{1}
uforecast rhat regend+1 regend+1
end do
At the end of this, the series RHAT will have a series of one-step out-of-sample forecasts over the period 1992:1 to 1994:12.
The last example used the same starting date for all regressions. Suppose, instead, you want to estimate over a “moving window” of, say, five years. There are various ways to handle the loop indexes to accomplish this—here’s one of them (this program also saves the estimated coefficients from each regression):
clear rhat coef1 coef2 coef3
do regend=1991:12,1994:11
linreg(noprint) logrsales regend-59 regend
# constant time logrsales{1}
compute coef1(regend) = %beta(1)
compute coef2(regend) = %beta(2)
compute coef3(regend) = %beta(3)
uforecast rhat regend+1 regend+1
end do
Both these examples compute only one-step-ahead forecasts, so saving the forecasts from each step in the rolling regression is easy. Suppose you instead want to compute twelve-step-ahead forecasts, and save only the twelfth forecast step from each rolling regression. If you simply did:
uforecast rhat regend+1 regend+12
then forecast step 12 from the first trip through the loop would be overwritten by forecast step 11 from the second trip through the loop, and so on. Thus an additional instruction is needed to copy the forecasts at later horizons to another series., as in
clear rhat rhat12
do regend=1991:12,1993:12
linreg(noprint) logrsales regend-59 regend
# constant time logrsales{1}
uforecast rhat regend+1 regend+12
compute rhat12(regend+12)=rhat(regend+12)
end do
Another way is to use FORECAST with the SKIPSAVE option, which is designed for just this sort of situation. For example:
clear rhat12
do regend=1991:1,1993:12
linreg(define=foreeq,noprint) logrsales regend-59 regend
# constant time logrsales{1}
forecast(skip=11,steps=12)
# foreeq rhat12
end do
See “Using the SKIPSAVE Option” for more information.
Copyright © 2025 Thomas A. Doan