* * Retail sales examples from pp 90-98 * cal(m) 1954:1 open data rsales.dat data(format=prn,org=columns) 1954:1 1994:12 * graph(footer="Figure 4.14 Retail Sales") # rsales * set time = t set time2 = t**2 * linreg rsales 1955:1 1993:12 # constant time @regcrits @regactfit(footer="Figure 4.15 Retail Sales: Linear Trend Residual Plot") * linreg rsales 1955:1 1993:12 # constant time time2 @regcrits @regactfit(footer="Figure 4.16 Retail Sales: Quadratic Trend Residual Plot") * set logrsales = log(rsales) linreg logrsales 1955:1 1993:12 # constant time @regcrits @regactfit(footer="Figure 4.17 Retail Sales: Log Linear Trend Residual Plot") * * Estimation of non-linear model using NLLS. The results in table 4.4 aren't the * best fit - as you can see, the RATS NLLS instruction gets a lower sum of * squared residuals. * nonlin b0 b1 frml etrend = b0*exp(b1*t) nlls(frml=etrend) rsales 1955:1 1993:12 @regcrits @regactfit(footer="Figure 4.18 Retail Sales: Exponential Trend Residual Plot") * * Create series which is 1's where we want shading * set y1994 = %year(t)==1994 * * Forecasts and 95% bands for quadratic trend forecasts * linreg rsales 1955:1 1993:12 # constant time time2 prj(stderrs=stderrs) qtrend 1994:1 1994:12 set upperq 1994:1 1994:12 = qtrend+1.96*stderrs set lowerq 1994:1 1994:12 = qtrend-1.96*stderrs * graph(footer="Figure 4.19 Retail Sales with Quadratic Trend Forecast",shading=y1994) 4 # rsales 1990:1 1993:12 # qtrend # upperq / 3 # lowerq / 3 * * Same thing, with actual sales through the forecast period * graph(footer="Figure 4.20 Retail Sales with Quadratic Trend Forecast and Realization",shading=y1994) 4 # rsales 1990:1 1994:12 # qtrend # upperq / 3 # lowerq / 3 * * Forecasts and 95% bands for linear trend forecasts * linreg rsales 1955:1 1993:12 # constant time prj(stderrs=stderrs) ltrend 1994:1 1994:12 set upperl 1994:1 1994:12 = ltrend+1.96*stderrs set lowerl 1994:1 1994:12 = ltrend-1.96*stderrs * graph(footer="Figure 4.21 Retail Sales with Linear Trend Forecast",shading=y1994) 4 # rsales 1990:1 1993:12 # ltrend # upperl / 3 # lowerl / 3 * * Same thing, with actual sales through the forecast period * graph(footer="Figure 4.22 Retail Sales with Linear Trend Forecast and Realization",shading=y1994) 4 # rsales 1990:1 1994:12 # ltrend # upperl / 3 # lowerl / 3 * * Generating Table 4.5 * We'll redo some of the results to build Table 4.5 using the REPORT instruction. * While this one is not very complicated, if you had a table with many more * values, you would rather not have to type the values in yourself. That's time * consuming, and errors aren't uncommon. (And, if it turns out that you, for * instance, used the wrong dependent variable, you might end up having to redo * the whole table). * * The report will have four columns: one which labels the rows, and one for each * model. The atrow and atcol show where information is to be placed. * fillby=columns means that the listed values fill a column beginning at the row * given by the atrow option. At the end, the report(action=format,picture="*.##") * formats the numbers to two decimal places, and report(action=show) displays the * completed report. * report(action=define,hlabels=||"","Linear Trend","Quadratic Trend","Exponential Trend"||) report(atrow=1,atcol=1,fillby=columns) "AIC" "SIC" linreg rsales 1955:1 1993:12 # constant time @regcrits report(atrow=1,atcol=2,fillby=columns) %aic %sbc linreg rsales 1955:1 1993:12 # constant time time2 @regcrits report(atrow=1,atcol=3,fillby=columns) %aic %sbc nonlin b0 b1 frml etrend = b0*exp(b1*t) nlls(frml=etrend) rsales 1955:1 1993:12 @regcrits report(atrow=1,atcol=4,fillby=columns) %aic %sbc report(action=format,picture="*.##") report(action=show,window="Table 4.5 Model Selection Criteria")