## LSTR with exogenous variables

Discussion of models with structural breaks or endogenous switching.

### LSTR with exogenous variables

Hi,

I am trying to fit a nonlinear LSTR fama regression of the form: x = (phi10 + phi1*zarfp) + (phi20 + phi2*zarfp)*{ [1 + exp(-gamma(zarfp - c))]^(-1) - 0.5} + u

x= exchange rate return of south african rand (ZARR)
zarfp=the forward premium of zar calculated as the forward 1-month rate minus the spot exchange rate
phi10 and phi20 are the constants

I also need to impose the following constraints: phi20 = - phi10 and phi2 = 1 - phi1

I used Terasvirta (1994) code and tried to modify it to use with this model. The modified code i used is the following:

Code: Select all
`***start of code***set x = zarrstats xcompute scalef=1.0/sqrt(%variance)*nonlin(parmset=starparms) gamma cfrml flstar = %logistic(scalef*gamma*(zarfp-c),1.0)compute c=%mean,gamma=2equation standard x#constant zarfpequation transit x#constant zarfp*frml(equation=standard,vector=phi1) phi1ffrml(equation=transit,vector=phi2) phi2ffrml star x = f=flstar,phi1f+f*phi2f*nonlin(parmset=regparms) phi1 phi2nonlin(parmset=starparms) gamma cnlls(parmet=regparms,frml=star) x*equation standard x#constant zarfpequation transit x#constant zarfpfrml(equation=standard,vector=phi1) phi1ffrml(equation=transit,vector=phi2) phi2fnlls(parmset=regparms,frml=star) xnlls(parmset=regparms+starparms,frml=star) x***end of code***`

It's the first time im implementing such a model and the results show that none of my coefficients are significant, which is doubtful. PLUS, when the code puts the regparms and starparms together to compute the actual final LSTR model it says NO CONVERGENCE IN 100 ITERATIONS. These are the results i obtains after running my code:

Code: Select all
`***results start***Nonlinear Least Squares - Estimation by Gauss-NewtonConvergence in     2 Iterations. Final criterion was  0.0000000 <=  0.0000100Dependent Variable XMonthly Data From 1983:10 To 2012:02Usable Observations                       247Degrees of Freedom                        243Skipped/Missing (from 341)                 94Centered R^2                        0.5534983R-Bar^2                             0.5479859Uncentered R^2                      0.5577250Mean of Dependent Variable       0.0038656906Std Error of Dependent Variable  0.0396237788Standard Error of Estimate       0.0266398556Sum of Squared Residuals         0.1724527029Regression F(3,243)                  100.4103Significance Level of F             0.0000000Log Likelihood                       546.9992Durbin-Watson Statistic                1.8625    Variable                        Coeff      Std Error      T-Stat      Signif************************************************************************************1.  PHI1(1)                      -0.030289521  0.013926828     -2.17490  0.030602112.  PHI1(2)                       0.800439097  0.314565158      2.54459  0.011560443.  PHI2(1)                       0.055678913  0.028139893      1.97865  0.048984994.  PHI2(2)                      -0.249856505  0.220355790     -1.13388  0.25796324Nonlinear Least Squares - Estimation by Gauss-NewtonConvergence in     2 Iterations. Final criterion was  0.0000000 <=  0.0000100Dependent Variable XMonthly Data From 1983:10 To 2012:02Usable Observations                       247Degrees of Freedom                        244Skipped/Missing (from 341)                 94Centered R^2                        0.5511359R-Bar^2                             0.5474567Uncentered R^2                      0.5553849Mean of Dependent Variable       0.0038656906Std Error of Dependent Variable  0.0396237788Standard Error of Estimate       0.0266554462Sum of Squared Residuals         0.1733651257Regression F(2,244)                  149.7972Significance Level of F             0.0000000Log Likelihood                       546.3475Durbin-Watson Statistic                1.8591    Variable                        Coeff      Std Error      T-Stat      Signif************************************************************************************1.  PHI1(1)                      -0.039251999  0.011473140     -3.42121  0.000730782.  PHI1(2)                       0.508067271  0.180282986      2.81817  0.005225833.  PHI2(1)                       0.072387915  0.023986914      3.01781  0.00281590Nonlinear Least Squares - Estimation by Gauss-NewtonNO CONVERGENCE IN 100 ITERATIONSLAST CRITERION WAS  0.0148635Dependent Variable XMonthly Data From 1983:10 To 2012:02Usable Observations                       247Degrees of Freedom                        242Skipped/Missing (from 341)                 94Centered R^2                        0.5586149R-Bar^2                             0.5513193Uncentered R^2                      0.5627931Mean of Dependent Variable       0.0038656906Std Error of Dependent Variable  0.0396237788Standard Error of Estimate       0.0265414470Sum of Squared Residuals         0.1704765151Log Likelihood                       548.4226Durbin-Watson Statistic                1.8022    Variable                        Coeff      Std Error      T-Stat      Signif************************************************************************************1.  PHI1(1)                       -1.56961890  27.93518244     -0.05619  0.955238492.  PHI1(2)                       -3.42856239  51.24802548     -0.06690  0.946715473.  PHI2(1)                        2.94346905  53.17023639      0.05536  0.955897874.  GAMMA                          0.27754188   1.97120718      0.14080  0.888146715.  C                             -0.02039801   0.08519234     -0.23943  0.81097111***end of results***`

My questions are the following:
- Is the choice of my starting values for gamma and c that are giving this outcome? Should i try others and see when convergence is reached?
- in my FRML, i specify vectors for phi1 and phi2. I did this to follow the Terasvirta code but i actually dont have a vector of coefficients since i only have in both my standard and transit equations a contant and one regressor (the zarfp). So how should i specify this?
- In this code i am not including the constrains as i am not too sure how to do it. From what i understood from the users guide, i should add the following after the nonlin(parmset=regparms) phi1 phi2: nonlin(parmset=constraints) phi10=-phi10 phi2=1-phi1

The problem, and i realize this, is that i havent specified phi10, only a vector phi1...so this must be wrong!

I would be incredibly grateful if you could help with this...i desperately need it!!

Ana
Ana_Rita

Posts: 13
Joined: Fri Apr 06, 2012 10:07 am

### Re: LSTR with exogenous variables

Ana_Rita wrote:Hi,

I am trying to fit a nonlinear LSTR fama regression of the form: x = (phi10 + phi1*zarfp) + (phi20 + phi2*zarfp)*{ [1 + exp(-gamma(zarfp - c))]^(-1) - 0.5} + u

x= exchange rate return of south african rand (ZARR)
zarfp=the forward premium of zar calculated as the forward 1-month rate minus the spot exchange rate
phi10 and phi20 are the constants

I also need to impose the following constraints: phi20 = - phi10 and phi2 = 1 - phi1

I used Terasvirta (1994) code and tried to modify it to use with this model. The modified code i used is the following:

Code: Select all
`***start of code***set x = zarrstats xcompute scalef=1.0/sqrt(%variance)*nonlin(parmset=starparms) gamma cfrml flstar = %logistic(scalef*gamma*(zarfp-c),1.0)compute c=%mean,gamma=2equation standard x#constant zarfpequation transit x#constant zarfp*frml(equation=standard,vector=phi1) phi1ffrml(equation=transit,vector=phi2) phi2ffrml star x = f=flstar,phi1f+f*phi2f*nonlin(parmset=regparms) phi1 phi2nonlin(parmset=starparms) gamma cnlls(parmet=regparms,frml=star) x*equation standard x#constant zarfpequation transit x#constant zarfpfrml(equation=standard,vector=phi1) phi1ffrml(equation=transit,vector=phi2) phi2fnlls(parmset=regparms,frml=star) xnlls(parmset=regparms+starparms,frml=star) x***end of code***`

It's the first time im implementing such a model and the results show that none of my coefficients are significant, which is doubtful. PLUS, when the code puts the regparms and starparms together to compute the actual final LSTR model it says NO CONVERGENCE IN 100 ITERATIONS. These are the results i obtains after running my code:

Code: Select all
`***results start***Nonlinear Least Squares - Estimation by Gauss-NewtonConvergence in     2 Iterations. Final criterion was  0.0000000 <=  0.0000100Dependent Variable XMonthly Data From 1983:10 To 2012:02Usable Observations                       247Degrees of Freedom                        243Skipped/Missing (from 341)                 94Centered R^2                        0.5534983R-Bar^2                             0.5479859Uncentered R^2                      0.5577250Mean of Dependent Variable       0.0038656906Std Error of Dependent Variable  0.0396237788Standard Error of Estimate       0.0266398556Sum of Squared Residuals         0.1724527029Regression F(3,243)                  100.4103Significance Level of F             0.0000000Log Likelihood                       546.9992Durbin-Watson Statistic                1.8625    Variable                        Coeff      Std Error      T-Stat      Signif************************************************************************************1.  PHI1(1)                      -0.030289521  0.013926828     -2.17490  0.030602112.  PHI1(2)                       0.800439097  0.314565158      2.54459  0.011560443.  PHI2(1)                       0.055678913  0.028139893      1.97865  0.048984994.  PHI2(2)                      -0.249856505  0.220355790     -1.13388  0.25796324Nonlinear Least Squares - Estimation by Gauss-NewtonConvergence in     2 Iterations. Final criterion was  0.0000000 <=  0.0000100Dependent Variable XMonthly Data From 1983:10 To 2012:02Usable Observations                       247Degrees of Freedom                        244Skipped/Missing (from 341)                 94Centered R^2                        0.5511359R-Bar^2                             0.5474567Uncentered R^2                      0.5553849Mean of Dependent Variable       0.0038656906Std Error of Dependent Variable  0.0396237788Standard Error of Estimate       0.0266554462Sum of Squared Residuals         0.1733651257Regression F(2,244)                  149.7972Significance Level of F             0.0000000Log Likelihood                       546.3475Durbin-Watson Statistic                1.8591    Variable                        Coeff      Std Error      T-Stat      Signif************************************************************************************1.  PHI1(1)                      -0.039251999  0.011473140     -3.42121  0.000730782.  PHI1(2)                       0.508067271  0.180282986      2.81817  0.005225833.  PHI2(1)                       0.072387915  0.023986914      3.01781  0.00281590Nonlinear Least Squares - Estimation by Gauss-NewtonNO CONVERGENCE IN 100 ITERATIONSLAST CRITERION WAS  0.0148635Dependent Variable XMonthly Data From 1983:10 To 2012:02Usable Observations                       247Degrees of Freedom                        242Skipped/Missing (from 341)                 94Centered R^2                        0.5586149R-Bar^2                             0.5513193Uncentered R^2                      0.5627931Mean of Dependent Variable       0.0038656906Std Error of Dependent Variable  0.0396237788Standard Error of Estimate       0.0265414470Sum of Squared Residuals         0.1704765151Log Likelihood                       548.4226Durbin-Watson Statistic                1.8022    Variable                        Coeff      Std Error      T-Stat      Signif************************************************************************************1.  PHI1(1)                       -1.56961890  27.93518244     -0.05619  0.955238492.  PHI1(2)                       -3.42856239  51.24802548     -0.06690  0.946715473.  PHI2(1)                        2.94346905  53.17023639      0.05536  0.955897874.  GAMMA                          0.27754188   1.97120718      0.14080  0.888146715.  C                             -0.02039801   0.08519234     -0.23943  0.81097111***end of results***`

My questions are the following:
- Is the choice of my starting values for gamma and c that are giving this outcome? Should i try others and see when convergence is reached?

I'm not seeing any reason your first two NLLS's are different. At any rate, you're losing the phi2(1) in the second and third NLLS, which could have something to do with it. The first NLLS seems reasonably well-behaved with the fixed values of c and gamma. However, if c and gamma aren't fixed, but are estimated, you could very easily have the switching coefficients go insignificant if the c and gamma themselves aren't well estimated.

Ana_Rita wrote:- in my FRML, i specify vectors for phi1 and phi2. I did this to follow the Terasvirta code but i actually dont have a vector of coefficients since i only have in both my standard and transit equations a contant and one regressor (the zarfp). So how should i specify this?

Just leave it the way it is.

Ana_Rita wrote:- In this code i am not including the constrains as i am not too sure how to do it. From what i understood from the users guide, i should add the following after the nonlin(parmset=regparms) phi1 phi2: nonlin(parmset=constraints) phi10=-phi10 phi2=1-phi1

The constraints are phi2(1)=-phi1(1) and phi2(2)=1-phi1(2)

Ana_Rita wrote:The problem, and i realize this, is that i havent specified phi10, only a vector phi1...so this must be wrong!

Your "phi10" is phi1(1) and "phi1" is phi1(2). Similarly for phi2's.
TomDoan

Posts: 2725
Joined: Wed Nov 01, 2006 5:36 pm

### Re: LSTR with exogenous variables

Thank you Tom so much for the prompt reply!!

After the first NLLS, since phi2(2) was insignificant, i took it off when re-estimating the NLLS again. Terasvirta's code does this as well so i tried it. But now i put it back so the full model appears in all NLLS.

What do you mean by "if the c and gamma coefficients aren't well estimated"? You mean if my starting values are too far from the true ones or do you mean if the function im using to model the nonlinearities in the model is wrong?

Also, i added the constraints and for the first NLLS that seems to work well! But i am now thinking that in the last line of my code --- "nlls(parmset=regparms+starparms,frml=star) x" --- i should add the constraints command again, in something that would look like this: "nlls(parmset=regparms+starparms+constraints,frml=star) x". I tried it, and got something not right! I must be missing something, sorry for this, it must be something really obvious im doing wrong with this!

But without adding the constraints in the last NLLS, my new code is now:

Code: Select all
`***start code***set x = zarrstats xcompute scalef=1.0/sqrt(%variance)*nonlin(parmset=starparms) gamma cfrml flstar = %logistic(scalef*gamma*(zarfp-c),1.0)compute c=%mean,gamma=2equation standard x#constant zarfpequation transit x#constant zarfp*frml(equation=standard,vector=phi1) phi1ffrml(equation=transit,vector=phi2) phi2ffrml star x = f=flstar,phi1f+f*phi2f*nonlin(parmset=regparms) phi1 phi2nonlin(parmset=constraints) phi2(1)=-phi1(1) phi2(2)=1-phi1(2)nonlin(parmset=starparms) gamma cnlls(parmet=regparms,frml=star) x*equation standard x#constant zarfpequation transit x#constant zarfpfrml(equation=standard,vector=phi1) phi1ffrml(equation=transit,vector=phi2) phi2fnlls(parmset=regparms,frml=star) xnlls(parmset=regparms+starparms,frml=star) x***end code***`

and the results from this are:

Code: Select all
`***start of results***Nonlinear Least Squares - Estimation by Gauss-NewtonConvergence in     2 Iterations. Final criterion was  0.0000000 <=  0.0000100Dependent Variable XMonthly Data From 1983:10 To 2012:02Usable Observations                       247Degrees of Freedom                        243Skipped/Missing (from 341)                 94Centered R^2                        0.5534989R-Bar^2                             0.5479865Uncentered R^2                      0.5577255Mean of Dependent Variable       0.0038656906Std Error of Dependent Variable  0.0396237788Standard Error of Estimate       0.0266398383Sum of Squared Residuals         0.1724524788Regression F(3,243)                  100.4105Significance Level of F             0.0000000Log Likelihood                       546.9994Durbin-Watson Statistic                1.8618    Variable                        Coeff      Std Error      T-Stat      Signif************************************************************************************1.  PHI1(1)                      -0.028798399  0.013261227     -2.17162  0.030851842.  PHI1(2)                       0.820885467  0.304180237      2.69868  0.007449893.  PHI2(1)                       0.054613510  0.027809333      1.96386  0.050686944.  PHI2(2)                      -0.274816519  0.212242526     -1.29482  0.19661021Nonlinear Least Squares - Estimation by Gauss-NewtonNO CONVERGENCE IN 100 ITERATIONSLAST CRITERION WAS  0.0061040Dependent Variable XMonthly Data From 1983:10 To 2012:02Usable Observations                       247Degrees of Freedom                        241Skipped/Missing (from 341)                 94Centered R^2                        0.5571299R-Bar^2                             0.5479417Uncentered R^2                      0.5613222Mean of Dependent Variable       0.0038656906Std Error of Dependent Variable  0.0396237788Standard Error of Estimate       0.0266411589Sum of Squared Residuals         0.1710500752Log Likelihood                       548.0078Durbin-Watson Statistic                1.8646    Variable                        Coeff      Std Error      T-Stat      Signif************************************************************************************1.  PHI1(1)                         -2.031226   128.525521     -0.01580  0.987403782.  PHI1(2)                        -16.771337  1112.602706     -0.01507  0.987985643.  PHI2(1)                          2.091723   128.696939      0.01625  0.987045934.  PHI2(2)                         17.160119  1111.810132      0.01543  0.987698395.  GAMMA                            0.956851     1.831588      0.52242  0.601860286.  C                               -0.160123     3.117359     -0.05136  0.95907723***end of results***`

- So, it still wont converge and i dont know why.
- Maybe because i need to add the constraints which are missing...?
- the reason i think there is still a procedure problem with my final model is because if i am not modelling correctly the nonlinearities, the linear part of the model should still give me some significant coefficients no?!

Many many thanks again for all your effort to understand all this!!
Ana
Ana_Rita

Posts: 13
Joined: Fri Apr 06, 2012 10:07 am

### Re: LSTR with exogenous variables

Ana_Rita wrote:Thank you Tom so much for the prompt reply!!

After the first NLLS, since phi2(2) was insignificant, i took it off when re-estimating the NLLS again. Terasvirta's code does this as well so i tried it. But now i put it back so the full model appears in all NLLS.

What do you mean by "if the c and gamma coefficients aren't well estimated"? You mean if my starting values are too far from the true ones or do you mean if the function im using to model the nonlinearities in the model is wrong?

Also, i added the constraints and for the first NLLS that seems to work well! But i am now thinking that in the last line of my code --- "nlls(parmset=regparms+starparms,frml=star) x" --- i should add the constraints command again, in something that would look like this: "nlls(parmset=regparms+starparms+constraints,frml=star) x". I tried it, and got something not right! I must be missing something, sorry for this, it must be something really obvious im doing wrong with this!

But without adding the constraints in the last NLLS, my new code is now:

Code: Select all
`***start code***set x = zarrstats xcompute scalef=1.0/sqrt(%variance)*nonlin(parmset=starparms) gamma cfrml flstar = %logistic(scalef*gamma*(zarfp-c),1.0)compute c=%mean,gamma=2equation standard x#constant zarfpequation transit x#constant zarfp*frml(equation=standard,vector=phi1) phi1ffrml(equation=transit,vector=phi2) phi2ffrml star x = f=flstar,phi1f+f*phi2f*nonlin(parmset=regparms) phi1 phi2nonlin(parmset=constraints) phi2(1)=-phi1(1) phi2(2)=1-phi1(2)nonlin(parmset=starparms) gamma cnlls(parmet=regparms,frml=star) x*equation standard x#constant zarfpequation transit x#constant zarfpfrml(equation=standard,vector=phi1) phi1ffrml(equation=transit,vector=phi2) phi2fnlls(parmset=regparms,frml=star) xnlls(parmset=regparms+starparms,frml=star) x***end code***`

and the results from this are:

Code: Select all
`***start of results***Nonlinear Least Squares - Estimation by Gauss-NewtonConvergence in     2 Iterations. Final criterion was  0.0000000 <=  0.0000100Dependent Variable XMonthly Data From 1983:10 To 2012:02Usable Observations                       247Degrees of Freedom                        243Skipped/Missing (from 341)                 94Centered R^2                        0.5534989R-Bar^2                             0.5479865Uncentered R^2                      0.5577255Mean of Dependent Variable       0.0038656906Std Error of Dependent Variable  0.0396237788Standard Error of Estimate       0.0266398383Sum of Squared Residuals         0.1724524788Regression F(3,243)                  100.4105Significance Level of F             0.0000000Log Likelihood                       546.9994Durbin-Watson Statistic                1.8618    Variable                        Coeff      Std Error      T-Stat      Signif************************************************************************************1.  PHI1(1)                      -0.028798399  0.013261227     -2.17162  0.030851842.  PHI1(2)                       0.820885467  0.304180237      2.69868  0.007449893.  PHI2(1)                       0.054613510  0.027809333      1.96386  0.050686944.  PHI2(2)                      -0.274816519  0.212242526     -1.29482  0.19661021Nonlinear Least Squares - Estimation by Gauss-NewtonNO CONVERGENCE IN 100 ITERATIONSLAST CRITERION WAS  0.0061040Dependent Variable XMonthly Data From 1983:10 To 2012:02Usable Observations                       247Degrees of Freedom                        241Skipped/Missing (from 341)                 94Centered R^2                        0.5571299R-Bar^2                             0.5479417Uncentered R^2                      0.5613222Mean of Dependent Variable       0.0038656906Std Error of Dependent Variable  0.0396237788Standard Error of Estimate       0.0266411589Sum of Squared Residuals         0.1710500752Log Likelihood                       548.0078Durbin-Watson Statistic                1.8646    Variable                        Coeff      Std Error      T-Stat      Signif************************************************************************************1.  PHI1(1)                         -2.031226   128.525521     -0.01580  0.987403782.  PHI1(2)                        -16.771337  1112.602706     -0.01507  0.987985643.  PHI2(1)                          2.091723   128.696939      0.01625  0.987045934.  PHI2(2)                         17.160119  1111.810132      0.01543  0.987698395.  GAMMA                            0.956851     1.831588      0.52242  0.601860286.  C                               -0.160123     3.117359     -0.05136  0.95907723***end of results***`

- So, it still wont converge and i dont know why.
- Maybe because i need to add the constraints which are missing...?
- the reason i think there is still a procedure problem with my final model is because if i am not modelling correctly the nonlinearities, the linear part of the model should still give me some significant coefficients no?!

Many many thanks again for all your effort to understand all this!!
Ana

Perhaps there is no clear threshold effect. If that's the case then gamma and c aren't identified so they (theoretically) would have infinite standard errors. Since their values aren't well determined, if they happen to end up giving a value for the threshold function of near 0 for most data points, then the 2 branch is a regression on (near) zeros, so its coefficients can be anything. And if they give threshold functions near 1 on most data points, then neither coefficient vector will be individually estimated---just their sum, as then you have near perfect collinearity. Terasvirta suggests grid searching to get the optimal value of c. However, once you have that, you still need to re-run with the full parameter set to get the proper standard errors, which could again cause the regression coefficients to go insignificant.

BTW, why are you losing 94 data points? Does your data not start in 1983?
TomDoan

Posts: 2725
Joined: Wed Nov 01, 2006 5:36 pm

### Re: LSTR with exogenous variables

Hi Tom!

Yes, my first thought was to do a grid search but i have no idea how to do it in RATS! Is there anything i could read to teach me how to implement it? I did this same model but with other countries 5 years ago for my masters and i used a code from GAUSS which got me very good results using a grid search. I dont have the code anymore and already at the time it was a nightmare working with GAUSS. Any suggestion on this will be immensely appreciated! Given that i am using some of the same countries as i did in my masters paper, i know that this model should work, suggesting that if it doesnt work now, i must be doing something wrong...

Also, sorry to ask again but, any thought on whether i have to add the constraints again when i NLLS for the final model and put all coefficients together?

About the loosing 94 observations thats expected because i have an excel file with the data for all my countries, and for some, data goes as far back as 1983 so i guess RATS reads it as the starting time for all my countries. Could that affect my results?

Many thanks for all your help so far!
Ana
Ana_Rita

Posts: 13
Joined: Fri Apr 06, 2012 10:07 am

### Re: LSTR with exogenous variables

I found something on the Programming Manual about doing a grid search for a TAR model. But it looks too different for me to try and do the same for a LSTR model, especially when they reach the "loop part", i would not know where to start!...
Ana_Rita

Posts: 13
Joined: Fri Apr 06, 2012 10:07 am

### Re: LSTR with exogenous variables

Hi,

i have simplified my LSTR model so that it looks like this now:

set y=zarr
set x=zarfp
stats x
set sd=sdzarfp

nonlin a1 a2 a3 a4 a5 gamma gamma.ge.0
frml lstar y = a1 + a2*x + (a3 + a4*x)/(1 + exp(-(gamma*(x-a5)/sd)))
com gamma=0.1, a2=-1, a4=1, a5=%mean
nlls(frml=lstar) y / u

Each time i run it, i keep changing the values of gamma from 0.1, 0.2, 0.3, 0.4, etc etc until about number 8 and i do get models that converge. Sometimes i also change the constraints a2 and a4 from -1 to +1 to see if it helps. The problem i have (apart from the fact that i have 10 countries and doing this for all of them is taking a long time) is that i manage to get the model to converge, but when it does, depending on the value i have chosen for gamma i get different results. They are all significant, so in the end i dont know which on to choose.

I know i can do a loop with "do i=1,10" and "end do i" over the model but them i would end up with 10 models and i would still have the same problem of not knowing how to choose the correct one.

I keep reading in papers that use the exact same model as me that they use a grid search to calculate the most efficient model but i still cant find any information on how to do a grid search on a LSTR model...If there is anything you can point out for me to read about this i would be very thankful, and i apologize for keep posting about this (this will be my last post on the subject!).

Many thanks anyways!
Ana
Ana_Rita

Posts: 13
Joined: Fri Apr 06, 2012 10:07 am

### Re: LSTR with exogenous variables

This does (towards the end) a preliminary grid search for the break value, then estimates the full model given the best value found. This is a constructed model, so the break is quite a bit sharper than you would see in practice.

Code: Select all
`** Enders, Applied Econometric Time Series, 3rd edition* Example from Section 7.9, pp 466-469* STAR models** This line (if uncommented) would generated 500 data points starting* with 0 as the initial value. You would use the last 250.**set(first=0.0) yg 1 500 = 1.0+.9*yg{1}+(-3.0-1.7*yg{1})*%logistic(10.0*(yg{1}-5.0),1.0)+%ran(1.0)*open data lstar.xlsdata(format=xls,org=columns) 1 250 entry ygraph(footer="Figure 7.10 The Simulated LSTAR Process")# y*stats y@bjident ylinreg y# constant y{1}@regcorrs(number=12)** This does the RESET test on the most recent regression.*@regreset(h=4)** The STAR test can be done using the @STARTEST procedure. This does the* regression described in the text and produces several test statistics.* The non-linearity test is an F-test of the three non-linear terms. H12* tests the joint significance of the squared and cubic terms and H03* tests the signficance of the fourth degree term. If the model were* ESTAR rather than LSTAR, the H03 would be expected to be insignificant.*@startest(p=1,d=1) y@startest(p=1,d=2) y** Estimate the LSTAR model*nonlin(parmset=starparms) gamma clinreg y# constant y{1}frml(vector=phi1,lastreg) phi1ffrml(vector=phi2,lastreg) phi2f*frml glstar = %logistic(gamma*(y{1}-c),1.0)frml star y = g=glstar,phi1f+g*phi2f** Use the sample mean and 2/sigma as the guess values for the STAR* parameters.*stats ycompute c=%meancompute gamma=2.0/sqrt(%variance)*nonlin(parmset=regparms) phi1 phi2** First, estimate the model with the STAR parameters left out.*nlls(frml=star,parmset=regparms) y** Now, re-estimate with both the regression parameters and the STAR* parameters.*nlls(frml=star,parmset=regparms+starparms) y** This does a preliminary grid search for c (estimating the other* parameters) then estimates a final model starting at the best value* found by the grid search.*stats(fractiles) ycompute grid=%seqa(%fract01,(%fract99-%fract01)/99.0,100)dec real cgridcompute minrss=1.e+100nonlin(parmset=starparms) gamma c=cgriddofor cgrid = grid   nlls(frml=star,parmset=regparms+starparms,noprint) y   if %rss<minrss      compute minrss=%rss,cbest=cgrid   disp c %rssend dofor cgrid*compute c=cbestnonlin(parmset=starparms) gamma cnlls(frml=star,parmset=regparms+starparms,print) y`

lstar.xls
Data file
TomDoan

Posts: 2725
Joined: Wed Nov 01, 2006 5:36 pm

### Re: LSTR with exogenous variables

Many many thanks Tom! I adapted your code to grid search for c in my model, then i also grid searched for gamma, then i also grid searched for both...No success, i cannot reach conversion in none of the cases i tried. So i think im just gonna move on!

In any case, you were of great help and i cannot thank you enough!
Ana
Ana_Rita

Posts: 13
Joined: Fri Apr 06, 2012 10:07 am

### Re: LSTR with exogenous variables

If you post your data and the program you're trying to run, I'll take a look at it.
TomDoan

Posts: 2725
Joined: Wed Nov 01, 2006 5:36 pm

### Re: LSTR with exogenous variables

Thank you

So basically i have 9 countries. I get convergence and ok results for HUF and ZAR - even thought when i test them for serial correlation the p-value is 0.000, so im not too sure what i cant do with them. Unless that low p-val is caused by not running the model properly...
Attachments
Grid search for STR - adapted from Tom.docx
WEEKLY.xlsx
Ana_Rita

Posts: 13
Joined: Fri Apr 06, 2012 10:07 am

### Re: LSTR with exogenous variables

Ana_Rita wrote:Thank you

So basically i have 9 countries. I get convergence and ok results for HUF and ZAR - even thought when i test them for serial correlation the p-value is 0.000, so im not too sure what i cant do with them. Unless that low p-val is caused by not running the model properly...

You have the ESTR function activated, not the LSTR. LSTR seems to fit OK, ESTR doesn't.
TomDoan

Posts: 2725
Joined: Wed Nov 01, 2006 5:36 pm

### Re: LSTR with exogenous variables

Yes you are right, for some reason the STR fits better. I tried to add gamma.ge.0 so that i wouldn't get negative values but it just keeps on giving me the same negative value. And for those countries where i get a positive value, its a gigantic one! I guess maybe the model is simply picking up outliers rather than showing a regime shift.

Anyways, i honestly couldn't have asked for a more efficient help!! Thank you for all the time you spent on this Tom!
Ana
Ana_Rita

Posts: 13
Joined: Fri Apr 06, 2012 10:07 am

### Re: LSTR with exogenous variables

Obviously ESTR and LSTR have very different behaviors since ESTR requires the same regression equation in both tails of the threshold variable, while LSTR has one regression in one tail and another in the other. ESTR models have a problem that isn't shared with LSTR, and which you might have been running into. If you have a major outlier (and you do), the ESTR transition can isolate it by pushing the gamma up to infinity while c goes to the X value at the outlier. The transition function then becomes a spike at that value of X, in effect, giving you a dummy variable taking out that data point, which, in the case of a very large outlier, could give you the best "fitting" model. With the LSTR transition, a very high value of gamma gives a step transition, but not a one data point spike.
TomDoan

Posts: 2725
Joined: Wed Nov 01, 2006 5:36 pm

### Re: LSTR with exogenous variables

Is that hinting at the use of a SETAR model instead, given the "step" transition?
Ana_Rita

Posts: 13
Joined: Fri Apr 06, 2012 10:07 am