Forecast TAR and AR model

Discussion of models with structural breaks or endogenous switching.
Brc
Posts: 18
Joined: Thu Jun 20, 2024 5:16 pm

Forecast TAR and AR model

Unread post by Brc »

Dear Tom,

Thank you for your helps during learning RATs for TAR model.

I also need to forecast AR model and TAR model, and I need to plot these forecasted TAR and AR models.
And I need to calculate Mean Error, Mean Absolute Error, Root Mean Square Error, Mean Square Error, and Theil's U for both the forecasted AR and TAR models.

My series is Z ~AR(9).
My TAR model is as follows:

Zt = It*(-010+0.29*Z1 + 0.55*Z2+0.29*Z4-0.2*Z7+ 0.22*Z9)+(1-It)*(0.53*Z1 + 0.12*Z5 + 0.15*Z8)

where threshold=0.009 and transition var=Z2 (=Z_t-2)

Code: Select all

***Linear Model Estmation*******
LINREG(PRINT) Z / RT
#  Z{1 5 7 9}
***
CORRELATE(QSTAT,NUMBER=12) RT
*
STATISTICS(print) RT
*
COMPUTE AKAIKE1 = LOG(%SEESQ)+(2.0*(%NREG))/(%NOBS)
COMPUTE AKAIKE2 = (%NOBS)*LOG(%SEESQ)+(2*(%NREG))
DISPLAY 'AKAIKE1' AKAIKE1 'AKAIKE2' AKAIKE2
*****
SET Z1 = Z{1}
SET Z2 = Z{2}
SET Z3 = Z{3}
SET Z4 = Z{4}
SET Z5 = Z{5}
SET Z6 = Z{6}
SET Z7 = Z{7}
SET Z8 = Z{8}
SET Z9 = Z{9}
***
**** Estimate TAR model with 2 regimes*********
**
COMPUTE LOW = 2003:2 + FIX(.15*%NOBS)
COMPUTE HIGH = 2025:2 - FIX(.15*%NOBS)
COMPUTE RSSTEST = 1000000.0
SET RSS = 0.
SET THRESHTEST = Z
ORDER THRESHTEST
COMPUTE THRESH = THRESHTEST(LOW)
DO I = LOW, HIGH
   SET G = %IF(Z{2}<THRESHTEST(I),0,1)
   SET R = 1 - G
**
**
   SET GZ1 = G*Z{1}
   SET GZ2 = G*Z{2}
   SET GZ3 = G*Z{3}
   SET GZ4 = G*Z{4}
   SET GZ5 = G*Z{5}
   SET GZ6 = G*Z{6}
   SET GZ7 = G*Z{7}
   SET GZ8 = G*Z{8}
   SET GZ9 = G*Z{9}
**
  ***********************
   SET RZ1 = R*Z{1}
   SET RZ2 = R*Z{2}
   SET RZ3 = R*Z{3}
   SET RZ4 = R*Z{4}
   SET RZ5 = R*Z{5}
   SET RZ6 = R*Z{6}
   SET RZ7 = R*Z{7}
   SET RZ8 = R*Z{8}
   SET RZ9 = R*Z{9}
**
**************
   LINREG(NOPRINT) Z
   # G GZ1 GZ2 GZ3 gz4 gz5 gz6 gz7 gz8 gz9 R RZ1 RZ2 RZ3 RZ4 RZ5 RZ6 RZ7 RZ8 RZ9
 **
   COM RSS(I) = %RSS
   IF %RSS < RSSTEST {
   	COMPUTE RSSTEST = %RSS
   	COMPUTE THRESH = THRESHTEST(i)
   }
ENDO DO I
DIS 'ATTRACTOR'
DIS 'THRESHOLD = ' THRESH
   ***
  SET G = %IF(z{2}<THRESH,0,1)
   SET R = 1 - G
  **
SET GZ1 = G*Z{1}
   SET GZ2 = G*Z{2}
   SET GZ3 = G*Z{3}
   SET GZ4 = G*Z{4}
   SET GZ5 = G*Z{5}
   SET GZ6 = G*Z{6}
   SET GZ7 = G*Z{7}
   SET GZ8 = G*Z{8}
   SET GZ9 = G*Z{9}
**
  ***********************
   SET RZ1 = R*Z{1}
   SET RZ2 = R*Z{2}
   SET RZ3 = R*Z{3}
   SET RZ4 = R*Z{4}
   SET RZ5 = R*Z{5}
   SET RZ6 = R*Z{6}
   SET RZ7 = R*Z{7}
   SET RZ8 = R*Z{8}
   SET RZ9 = R*Z{9}
**
LINREG(PRINT, frml=tarmodel) Z
   # G GZ1 GZ2  GZ4  GZ6 GZ7 GZ9  RZ1 RZ5 RZ8
 **
***********
sca(Header='Residual Sums of Squares',style=lines,hlabel='Threshold') 1 ;
#  threshtest rss low high

However, I could wrote down codes to forecast AR model and TAR model, graph these forecasted models together and to calculate Mean Error, Mean Absolute Error, Root Mean Square Error, Mean Square Error, and Theil's U for both the forecasted AR and TAR models.

Can you please help me for this?

Thank you so much for your great helps.

Best Regards.
TomDoan
Posts: 7776
Joined: Wed Nov 01, 2006 4:36 pm

Re: Forecast TAR and AR model

Unread post by TomDoan »

An AR model is easy to forecast. A TAR, not so much. Pretty much any non-linear model needs simulation methods to do forecasts.

https://estima.com/webhelp/topics/thres ... sions.html

A TAR (as opposed to a STAR) has the additional complication that the model estimates a hard threshold value at one of the data values but has no ability to determine to which regime an entry belongs if the threshold series lies between the estimated threshold value and the next larger observed value (since there is no observation in the data set with a value in that range).

The lynxforecast.rpf program in the Terasvirta 1994 replication shows both the calculation of the "eventual forecast function" (which is the calculation without any shocks) and a forecast by simulation. Note that these models take a VERY large number of simulations before the mean settles down. That example does 1000, but you would probably need 10000 or even 100000 before you would feel confident in comparing the forecasts to an AR where the forecasts can be computed exactly.
Post Reply