About TAR model: Chan's method to select threshold value

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

About TAR model: Chan's method to select threshold value

Unread post by Brc »

Hello Dear Tom,

I have a question about TAR model. My series is Z and period is from 2003:2 to 2025:2 (monthly/ 265 observations).

The lag order of Z is 9. That's, Z ~AR(9) by AIC. I have determined transition variable as Z{2}.

Now, I need to apply Chan's method to select threshold value. That's, for linear attractor model, I need to find best SSQ and threshold values. For that, I wrote down two RATs codes, but I got wrong results.

Code: Select all

***
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}
***
The code:

Code: Select all

compute low = 2003:2 + fix(.15*%nobs) , high = 2025:2 - fix(.15*%nobs)
compute rss_test = 1000000.0
set rss = 0.
set thresh_test = Z
order thresh_test
compute thresh = thresh_test(low)
do i = low,high
   set plus = %if(z{2}<thresh_test(i),0,1)
   set minus = 1 - plus
   set Z1_plus = plus*z{1}
   set Z2_plus = plus*z{2}
   set Z3_plus = plus*z{3}
   set Z4_plus = plus*z{4}
   set Z5_plus = plus*z{5}
   set Z6_plus = plus*z{6}
   set Z7_plus = plus*z{7}
   set Z8_plus = plus*z{8}
   set Z9_plus = plus*z{9}

************************
  set Z1_minus = minus* z{1}
  set Z2_minus = minus* z{2}
  set Z3_minus = minus* z{3}
  set Z4_minus = minus* z{4}
  set Z5_minus = minus* z{5}
  set Z6_minus = minus* z{6}
  set Z7_minus = minus* z{7}
  set Z8_minus = minus* z{8}
  set Z9_minus = minus* z{9}

*******
   lin(noprint) z
# plus z1_plus z2_plus Z3_plus Z4_plus Z5_plus Z6_plus Z7_plus Z8_plus Z9_plus  $
MINUS Z1_minus Z2_minus Z3_minus Z4_minus Z5_minus Z6_minus Z7_minus Z8_minus Z9_minus
***
com rss(i) = %rss
   if %rss < rss_test {
   	compute rss_test = %rss
   	compute thresh = thresh_test(i)
   }
end do i
dis 'We have found the attractor'
dis ' Threshold = ' thresh
   set plus = %if(z{2}<THRESH,0,1)
   set minus = 1 - plus
   set Z1_plus = plus*z{1}
   set Z2_plus = plus*z{2}
   set Z3_plus = plus*z{3}
   set Z4_plus = plus*z{4}
   set Z5_plus = plus*z{5}
   set Z6_plus = plus*z{6}
   set Z7_plus = plus*z{7}
   set Z8_plus = plus*z{8}
   set Z9_plus = plus*z{9}

************************
  set Z1_minus = minus* z{1}
  set Z2_minus = minus* z{2}
  set Z3_minus = minus* z{3}
  set Z4_minus = minus* z{4}
  set Z5_minus = minus* z{5}
  set Z6_minus = minus* z{6}
  set Z7_minus = minus* z{7}
  set Z8_minus = minus* z{8}
  set Z9_minus = minus* z{9}

*******
LINREG(print) z
# plus z1_plus z2_plus Z3_plus Z4_plus Z5_plus Z6_plus Z7_plus Z8_plus Z9_plus  $
MINUS Z1_minus Z2_minus Z3_minus Z4_minus Z5_minus Z6_minus Z7_minus Z8_minus Z9_minus

sca(Header='Residual Sums of Squares',style=lines,hlabel='Threshold') 1 ;
#  thresh_test rss low high



My question:

The code gives error as follows:
Can't Interpret SERIES[REAL] = SERIES[REAL]
## SX27. Illegal Combination of Data Types for Operation
>>>> + fix(.15*%nobs) ,<<<<

When I wrote down "SET low = 2003:02 + fix(.15*%nobs) , high = 2025:02 - fix(.15*%nobs)" in the first code, then I got an incorrect result. And I got the following wrong graph which I attached.



How can I correct these codes? or Which code should I use?

Thank you so much for your helps,

Best.
Attachments
Untitled_graph.jpeg
Untitled_graph.jpeg (68.37 KiB) Viewed 22463 times
TomDoan
Posts: 7779
Joined: Wed Nov 01, 2006 4:36 pm

Re: About TAR model: Chan's method to select threshold value

Unread post by TomDoan »

You'll have to post the full program. It looks like LOW and HIGH are being interpreted as SERIES.
Brc
Posts: 18
Joined: Thu Jun 20, 2024 5:16 pm

Re: About TAR model: Chan's method to select threshold value

Unread post by Brc »

Code: Select all

OPEN DATA "/Users/brc/Desktop/TAR_Study/Tar model_data.xlsx"
CALENDAR(M) 2003:2
DATA(FORMAT=XLSX,ORG=COLUMNS) 2003:02 2025:02 Z
***
Table
***
STATS  Z
***
******Select Lag Order*******
SOURCE C:\RATS-PROCEDURES\lagselec.src
@lagselect(sclag=24, maxo=24)  Z
**************
***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
****ARCH Effect Test
@archtest(lags=9,form=lm,span=1) RT
******
***
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}
***
*******BRUCE HANSEN 1987 METHOD*******
SOURCE C:\RATS-PROCEDURES\THRESHOLD.SRC

@THRESHTEST(THRESH=Z2,TRIM=0.15,GRAPH,NREPS=5000) Z
#constant Z{1 to 9}
************************************
DISPLAY 'CDSTAT' %CDSTAT 'SIGNIF' %SIGNIF
************************************************
***CHAN'S METHOD***********

SOURCE C:\RATS-PROCEDURES\TAR.SRC
@TAR(P=9,NREP=2000) Z
******************************************
******************************************
****Arranged Autoregression Test*****
SMPL 2005:02 2025:02
SOURCE C:\RATS-PROCEDURES\tsaytest.src
DO I=1,9,1
SET THR = Z{i}
@tsaytest( threshold=THR) Z
#constant Z{1 to 9}
END DO i

********

***For Linear Attractor model, we find best SSQ and threshold value.*****

compute low = 2003:2 + fix(.15*%nobs)
compute high =  2025:2 - fix(.15*%nobs)
compute rss_test = 1000000.0
set rss = 0.
set thresh_test = Z
order thresh_test
compute thresh = thresh_test(low)
do i = low,high
   set plus = %if(z{2}<thresh_test(i),0,1)
   set minus = 1 - plus
   set Z1_plus = plus*z{1}
   set Z2_plus = plus*z{2}
   set Z3_plus = plus*z{3}
   set Z4_plus = plus*z{4}
   set Z5_plus = plus*z{5}
   set Z6_plus = plus*z{6}
   set Z7_plus = plus*z{7}
   set Z8_plus = plus*z{8}
   set Z9_plus = plus*z{9}

************************
  set Z1_minus = minus* z{1}
  set Z2_minus = minus* z{2}
  set Z3_minus = minus* z{3}
  set Z4_minus = minus* z{4}
  set Z5_minus = minus* z{5}
  set Z6_minus = minus* z{6}
  set Z7_minus = minus* z{7}
  set Z8_minus = minus* z{8}
  set Z9_minus = minus* z{9}

*******
   lin(noprint) z
# plus z1_plus z2_plus Z3_plus Z4_plus Z5_plus Z6_plus Z7_plus Z8_plus Z9_plus  $
minus Z1_minus Z2_minus Z3_minus Z4_minus Z5_minus Z6_minus Z7_minus Z8_minus Z9_minus
***
com rss(i) = %rss
   if %rss < rss_test {
   	compute rss_test = %rss
   	compute thresh = thresh_test(i)
   }
end do i
dis 'We have found the attractor'
dis ' Threshold = ' thresh
****
*********
  set plus = %if(z{2}<THRESH,0,1)
   set minus = 1 - plus
   set Z1_plus = plus*z{1}
   set Z2_plus = plus*z{2}
   set Z3_plus = plus*z{3}
   set Z4_plus = plus*z{4}
   set Z5_plus = plus*z{5}
   set Z6_plus = plus*z{6}
   set Z7_plus = plus*z{7}
   set Z8_plus = plus*z{8}
   set Z9_plus = plus*z{9}

************************
  set Z1_minus = minus* z{1}
  set Z2_minus = minus* z{2}
  set Z3_minus = minus* z{3}
  set Z4_minus = minus* z{4}
  set Z5_minus = minus* z{5}
  set Z6_minus = minus* z{6}
  set Z7_minus = minus* z{7}
  set Z8_minus = minus* z{8}
  set Z9_minus = minus* z{9}

*******
LINREG(print) z
# plus z1_plus z2_plus Z3_plus Z4_plus Z5_plus Z6_plus Z7_plus Z8_plus Z9_plus  $
MINUS Z1_minus Z2_minus Z3_minus Z4_minus Z5_minus Z6_minus Z7_minus Z8_minus Z9_minus

sca(Header='Residual Sums of Squares',style=lines,hlabel='Threshold') 1 ;
#  thresh_test rss low high

*******************
I posted my whole code. And I attached dataset both in Excel file and in RATSdata format. I could not solve the problem. How can I deal with this problem. Thank you so much.

Best regards.
Attachments
Tar model_data.xlsx
(14.51 KiB) Downloaded 410 times
TARmodel_z.rat
(2.75 KiB) Downloaded 404 times
TomDoan
Posts: 7779
Joined: Wed Nov 01, 2006 4:36 pm

Re: About TAR model: Chan's method to select threshold value

Unread post by TomDoan »

I'm not reproducing an error if I run your whole program through in one go. (Edit---Select All, then Enter or hit the Run toolbar).

However, is there any reason you expect a TAR to be appropriate? When I look at the data, it looks clear that there is likely a structural break around 2017 which increases both the mean and (even more so) the variance. I don't see any of the asymmetrical cycle behavior that is generated by a non-linear autoregression. I would suggest you read the quick introduction to switching models in the help:

https://estima.com/webhelp/topics/switchingmodels.html
Brc
Posts: 18
Joined: Thu Jun 20, 2024 5:16 pm

Re: About TAR model: Chan's method to select threshold value

Unread post by Brc »

Dear Tom, Thank you for your attention and for taking the time to help me. I see my mistake.
Post Reply