<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Hansen's threshold regression in SAS Forecasting and Econometrics</title>
    <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Hansen-s-threshold-regression/m-p/836221#M4522</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/433513"&gt;@LynnChen&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At this time, there is no procedure that provides canned routine for Hansen(2000)'s threshold regression model directly. We may consider this functionality in the future, but at this time, you may consider following options:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For two regimes threshold regression like the following:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASCom1_0-1664572017175.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75771iDF5B7591F336F2B6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASCom1_0-1664572017175.png" alt="SASCom1_0-1664572017175.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you may perform the estimation by looping over all possible gammas(or a grid of gammas) as discussed below:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Get distinct w_t and sort them. assume they are {w_(i), i=1,…,T}, where w_(i) is the i-th smallest w. (that’s, all w_t are different, and T is the sample size).&lt;/LI&gt;
&lt;LI&gt;OLS regression y on (x, z), and record SSR as SSR_0.&lt;/LI&gt;
&lt;LI&gt;For i = 1 to T, OLS regress y on (x, u1, u2), where u1_t=z_t and u2_t=0 if w_t&amp;lt;=w_(i); otherwise, u1_t=0 and u2_t=z_t, and record SSR as SSR_i.&lt;/LI&gt;
&lt;LI&gt;Find the smallest SSR among SSR_i, i=0, …, T and the corresponding i; that’s, SSR_iStar&amp;lt;=SSR_i for any i.&lt;/LI&gt;
&lt;LI&gt;If i=0, no regime is needed; otherwise, gamma_hat=w_(iStar)&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If T is big, take a grid of w_i; e.g., i might be in the range of 10%*T and 90%*T.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For multiple regimes, the combination of gammas should be looped over---but in that case, maybe the new procedure PROC BART is a better choice,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/v_027/casstat/casstat_bart_details02.htm" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/v_027/casstat/casstat_bart_details02.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another alternative is similar to the following PROC MODEL switching regression example:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/v_031/etsug/etsug_model_sect280.htm" target="_blank"&gt;SAS Help Center: Switching Regression Example&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;which may provide an easier way to estimate this model, if you can accept that the solution is achieved by approximating the step function as the continuous function ProbNorm(.)&amp;nbsp; &amp;nbsp;--Note that this is a nonlinear optimization problem and the initial values or optimization method might matter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Following is an example that estimates the threshold model using the PROC MODEL approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;title1 'Threshold Regression Example';

data switch;
   call streaminit('pcg', 12345);
   do t = 1 to 1000;
      e = rand('normal');
      x = rand('normal');
      z = rand('normal');
      w = rand('uniform');
      if(w&amp;lt;0.345) then y = 1 + 1.5*x + 2 * z + 0.5*e;
      else y = 1 + 1.5*x - 2 * z + 0.5*e;
      mylogL = (1/2)*( (log(2*3.1415)) +
        log( 0.5**2 )
       + ((0.5*e)*( 1/0.5**2 )*(0.5*e)) ) ;
      output;
   end;
run;
proc means data=switch; var mylogL; run;

proc model data=switch;
   parms sig1=1 int1 b1 b21 b22 gamma=0.5;
   bounds 0.0001 &amp;lt; sig1;

   a = (w - gamma)*100;   /* Upper bound of integral */
   d = probnorm(a);       /* Normal CDF as an approx of switch */

                          /* Regime 1 */
   y1 = int1 + x * b1 + z * b21 ;
                          /* Regime 2 */
   y2 = int1 + x * b1 + z * b22 ;
                          /* Composite regression equation */
   y  = (1 - d)*y1 +  d*y2;

                         /* Resulting log-likelihood function */
   logL = (1/2)*( (log(2*3.1415)) +
        log( sig1**2 )
       + (resid.y*( 1/sig1**2 )*resid.y) ) ;

   errormodel y ~ general(logL);

   fit y / method=marquardt converge=1.0e-6;

run;
quit;


&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this helps!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 30 Sep 2022 21:27:19 GMT</pubDate>
    <dc:creator>SASCom1</dc:creator>
    <dc:date>2022-09-30T21:27:19Z</dc:date>
    <item>
      <title>Hansen's threshold regression</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Hansen-s-threshold-regression/m-p/832738#M4505</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Does anyone have any idea about&amp;nbsp;performing Hansen's threshold regression in SAS?&lt;/P&gt;&lt;P&gt;Or how can I find the document about it on the SAS platform?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Lynn&lt;/P&gt;</description>
      <pubDate>Sun, 11 Sep 2022 10:22:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Hansen-s-threshold-regression/m-p/832738#M4505</guid>
      <dc:creator>LynnChen</dc:creator>
      <dc:date>2022-09-11T10:22:41Z</dc:date>
    </item>
    <item>
      <title>Re: Hansen's threshold regression</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Hansen-s-threshold-regression/m-p/836221#M4522</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/433513"&gt;@LynnChen&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At this time, there is no procedure that provides canned routine for Hansen(2000)'s threshold regression model directly. We may consider this functionality in the future, but at this time, you may consider following options:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For two regimes threshold regression like the following:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASCom1_0-1664572017175.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75771iDF5B7591F336F2B6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASCom1_0-1664572017175.png" alt="SASCom1_0-1664572017175.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you may perform the estimation by looping over all possible gammas(or a grid of gammas) as discussed below:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Get distinct w_t and sort them. assume they are {w_(i), i=1,…,T}, where w_(i) is the i-th smallest w. (that’s, all w_t are different, and T is the sample size).&lt;/LI&gt;
&lt;LI&gt;OLS regression y on (x, z), and record SSR as SSR_0.&lt;/LI&gt;
&lt;LI&gt;For i = 1 to T, OLS regress y on (x, u1, u2), where u1_t=z_t and u2_t=0 if w_t&amp;lt;=w_(i); otherwise, u1_t=0 and u2_t=z_t, and record SSR as SSR_i.&lt;/LI&gt;
&lt;LI&gt;Find the smallest SSR among SSR_i, i=0, …, T and the corresponding i; that’s, SSR_iStar&amp;lt;=SSR_i for any i.&lt;/LI&gt;
&lt;LI&gt;If i=0, no regime is needed; otherwise, gamma_hat=w_(iStar)&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If T is big, take a grid of w_i; e.g., i might be in the range of 10%*T and 90%*T.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For multiple regimes, the combination of gammas should be looped over---but in that case, maybe the new procedure PROC BART is a better choice,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/v_027/casstat/casstat_bart_details02.htm" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/v_027/casstat/casstat_bart_details02.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another alternative is similar to the following PROC MODEL switching regression example:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/v_031/etsug/etsug_model_sect280.htm" target="_blank"&gt;SAS Help Center: Switching Regression Example&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;which may provide an easier way to estimate this model, if you can accept that the solution is achieved by approximating the step function as the continuous function ProbNorm(.)&amp;nbsp; &amp;nbsp;--Note that this is a nonlinear optimization problem and the initial values or optimization method might matter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Following is an example that estimates the threshold model using the PROC MODEL approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;title1 'Threshold Regression Example';

data switch;
   call streaminit('pcg', 12345);
   do t = 1 to 1000;
      e = rand('normal');
      x = rand('normal');
      z = rand('normal');
      w = rand('uniform');
      if(w&amp;lt;0.345) then y = 1 + 1.5*x + 2 * z + 0.5*e;
      else y = 1 + 1.5*x - 2 * z + 0.5*e;
      mylogL = (1/2)*( (log(2*3.1415)) +
        log( 0.5**2 )
       + ((0.5*e)*( 1/0.5**2 )*(0.5*e)) ) ;
      output;
   end;
run;
proc means data=switch; var mylogL; run;

proc model data=switch;
   parms sig1=1 int1 b1 b21 b22 gamma=0.5;
   bounds 0.0001 &amp;lt; sig1;

   a = (w - gamma)*100;   /* Upper bound of integral */
   d = probnorm(a);       /* Normal CDF as an approx of switch */

                          /* Regime 1 */
   y1 = int1 + x * b1 + z * b21 ;
                          /* Regime 2 */
   y2 = int1 + x * b1 + z * b22 ;
                          /* Composite regression equation */
   y  = (1 - d)*y1 +  d*y2;

                         /* Resulting log-likelihood function */
   logL = (1/2)*( (log(2*3.1415)) +
        log( sig1**2 )
       + (resid.y*( 1/sig1**2 )*resid.y) ) ;

   errormodel y ~ general(logL);

   fit y / method=marquardt converge=1.0e-6;

run;
quit;


&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this helps!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2022 21:27:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Hansen-s-threshold-regression/m-p/836221#M4522</guid>
      <dc:creator>SASCom1</dc:creator>
      <dc:date>2022-09-30T21:27:19Z</dc:date>
    </item>
  </channel>
</rss>

