Page 1 of 1

LSTR with exogenous variables

Posted: Fri Apr 06, 2012 12:16 pm
by Ana_Rita
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 = zarr
stats x
compute scalef=1.0/sqrt(%variance)
*
nonlin(parmset=starparms) gamma c
frml flstar = %logistic(scalef*gamma*(zarfp-c),1.0)
compute c=%mean,gamma=2
equation standard x
#constant zarfp
equation transit x
#constant zarfp
*
frml(equation=standard,vector=phi1) phi1f
frml(equation=transit,vector=phi2) phi2f
frml star x = f=flstar,phi1f+f*phi2f
*
nonlin(parmset=regparms) phi1 phi2
nonlin(parmset=starparms) gamma c
nlls(parmet=regparms,frml=star) x
*
equation standard x
#constant zarfp
equation transit x
#constant zarfp
frml(equation=standard,vector=phi1) phi1f
frml(equation=transit,vector=phi2) phi2f
nlls(parmset=regparms,frml=star) x
nlls(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-Newton
Convergence in     2 Iterations. Final criterion was  0.0000000 <=  0.0000100
Dependent Variable X
Monthly Data From 1983:10 To 2012:02
Usable Observations                       247
Degrees of Freedom                        243
Skipped/Missing (from 341)                 94
Centered R^2                        0.5534983
R-Bar^2                             0.5479859
Uncentered R^2                      0.5577250
Mean of Dependent Variable       0.0038656906
Std Error of Dependent Variable  0.0396237788
Standard Error of Estimate       0.0266398556
Sum of Squared Residuals         0.1724527029
Regression F(3,243)                  100.4103
Significance Level of F             0.0000000
Log Likelihood                       546.9992
Durbin-Watson Statistic                1.8625

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
1.  PHI1(1)                      -0.030289521  0.013926828     -2.17490  0.03060211
2.  PHI1(2)                       0.800439097  0.314565158      2.54459  0.01156044
3.  PHI2(1)                       0.055678913  0.028139893      1.97865  0.04898499
4.  PHI2(2)                      -0.249856505  0.220355790     -1.13388  0.25796324

Nonlinear Least Squares - Estimation by Gauss-Newton
Convergence in     2 Iterations. Final criterion was  0.0000000 <=  0.0000100
Dependent Variable X
Monthly Data From 1983:10 To 2012:02
Usable Observations                       247
Degrees of Freedom                        244
Skipped/Missing (from 341)                 94
Centered R^2                        0.5511359
R-Bar^2                             0.5474567
Uncentered R^2                      0.5553849
Mean of Dependent Variable       0.0038656906
Std Error of Dependent Variable  0.0396237788
Standard Error of Estimate       0.0266554462
Sum of Squared Residuals         0.1733651257
Regression F(2,244)                  149.7972
Significance Level of F             0.0000000
Log Likelihood                       546.3475
Durbin-Watson Statistic                1.8591

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
1.  PHI1(1)                      -0.039251999  0.011473140     -3.42121  0.00073078
2.  PHI1(2)                       0.508067271  0.180282986      2.81817  0.00522583
3.  PHI2(1)                       0.072387915  0.023986914      3.01781  0.00281590


Nonlinear Least Squares - Estimation by Gauss-Newton
NO CONVERGENCE IN 100 ITERATIONS
LAST CRITERION WAS  0.0148635
Dependent Variable X
Monthly Data From 1983:10 To 2012:02
Usable Observations                       247
Degrees of Freedom                        242
Skipped/Missing (from 341)                 94
Centered R^2                        0.5586149
R-Bar^2                             0.5513193
Uncentered R^2                      0.5627931
Mean of Dependent Variable       0.0038656906
Std Error of Dependent Variable  0.0396237788
Standard Error of Estimate       0.0265414470
Sum of Squared Residuals         0.1704765151
Log Likelihood                       548.4226
Durbin-Watson Statistic                1.8022

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
1.  PHI1(1)                       -1.56961890  27.93518244     -0.05619  0.95523849
2.  PHI1(2)                       -3.42856239  51.24802548     -0.06690  0.94671547
3.  PHI2(1)                        2.94346905  53.17023639      0.05536  0.95589787
4.  GAMMA                          0.27754188   1.97120718      0.14080  0.88814671
5.  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!!

Many thanks in advance!
Ana

Re: LSTR with exogenous variables

Posted: Fri Apr 06, 2012 1:54 pm
by TomDoan
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 = zarr
stats x
compute scalef=1.0/sqrt(%variance)
*
nonlin(parmset=starparms) gamma c
frml flstar = %logistic(scalef*gamma*(zarfp-c),1.0)
compute c=%mean,gamma=2
equation standard x
#constant zarfp
equation transit x
#constant zarfp
*
frml(equation=standard,vector=phi1) phi1f
frml(equation=transit,vector=phi2) phi2f
frml star x = f=flstar,phi1f+f*phi2f
*
nonlin(parmset=regparms) phi1 phi2
nonlin(parmset=starparms) gamma c
nlls(parmet=regparms,frml=star) x
*
equation standard x
#constant zarfp
equation transit x
#constant zarfp
frml(equation=standard,vector=phi1) phi1f
frml(equation=transit,vector=phi2) phi2f
nlls(parmset=regparms,frml=star) x
nlls(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-Newton
Convergence in     2 Iterations. Final criterion was  0.0000000 <=  0.0000100
Dependent Variable X
Monthly Data From 1983:10 To 2012:02
Usable Observations                       247
Degrees of Freedom                        243
Skipped/Missing (from 341)                 94
Centered R^2                        0.5534983
R-Bar^2                             0.5479859
Uncentered R^2                      0.5577250
Mean of Dependent Variable       0.0038656906
Std Error of Dependent Variable  0.0396237788
Standard Error of Estimate       0.0266398556
Sum of Squared Residuals         0.1724527029
Regression F(3,243)                  100.4103
Significance Level of F             0.0000000
Log Likelihood                       546.9992
Durbin-Watson Statistic                1.8625

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
1.  PHI1(1)                      -0.030289521  0.013926828     -2.17490  0.03060211
2.  PHI1(2)                       0.800439097  0.314565158      2.54459  0.01156044
3.  PHI2(1)                       0.055678913  0.028139893      1.97865  0.04898499
4.  PHI2(2)                      -0.249856505  0.220355790     -1.13388  0.25796324

Nonlinear Least Squares - Estimation by Gauss-Newton
Convergence in     2 Iterations. Final criterion was  0.0000000 <=  0.0000100
Dependent Variable X
Monthly Data From 1983:10 To 2012:02
Usable Observations                       247
Degrees of Freedom                        244
Skipped/Missing (from 341)                 94
Centered R^2                        0.5511359
R-Bar^2                             0.5474567
Uncentered R^2                      0.5553849
Mean of Dependent Variable       0.0038656906
Std Error of Dependent Variable  0.0396237788
Standard Error of Estimate       0.0266554462
Sum of Squared Residuals         0.1733651257
Regression F(2,244)                  149.7972
Significance Level of F             0.0000000
Log Likelihood                       546.3475
Durbin-Watson Statistic                1.8591

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
1.  PHI1(1)                      -0.039251999  0.011473140     -3.42121  0.00073078
2.  PHI1(2)                       0.508067271  0.180282986      2.81817  0.00522583
3.  PHI2(1)                       0.072387915  0.023986914      3.01781  0.00281590


Nonlinear Least Squares - Estimation by Gauss-Newton
NO CONVERGENCE IN 100 ITERATIONS
LAST CRITERION WAS  0.0148635
Dependent Variable X
Monthly Data From 1983:10 To 2012:02
Usable Observations                       247
Degrees of Freedom                        242
Skipped/Missing (from 341)                 94
Centered R^2                        0.5586149
R-Bar^2                             0.5513193
Uncentered R^2                      0.5627931
Mean of Dependent Variable       0.0038656906
Std Error of Dependent Variable  0.0396237788
Standard Error of Estimate       0.0265414470
Sum of Squared Residuals         0.1704765151
Log Likelihood                       548.4226
Durbin-Watson Statistic                1.8022

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
1.  PHI1(1)                       -1.56961890  27.93518244     -0.05619  0.95523849
2.  PHI1(2)                       -3.42856239  51.24802548     -0.06690  0.94671547
3.  PHI2(1)                        2.94346905  53.17023639      0.05536  0.95589787
4.  GAMMA                          0.27754188   1.97120718      0.14080  0.88814671
5.  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.

Re: LSTR with exogenous variables

Posted: Fri Apr 06, 2012 2:44 pm
by Ana_Rita
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 = zarr
stats x
compute scalef=1.0/sqrt(%variance)
*
nonlin(parmset=starparms) gamma c
frml flstar = %logistic(scalef*gamma*(zarfp-c),1.0)
compute c=%mean,gamma=2
equation standard x
#constant zarfp
equation transit x
#constant zarfp
*
frml(equation=standard,vector=phi1) phi1f
frml(equation=transit,vector=phi2) phi2f
frml star x = f=flstar,phi1f+f*phi2f
*
nonlin(parmset=regparms) phi1 phi2
nonlin(parmset=constraints) phi2(1)=-phi1(1) phi2(2)=1-phi1(2)
nonlin(parmset=starparms) gamma c
nlls(parmet=regparms,frml=star) x
*
equation standard x
#constant zarfp
equation transit x
#constant zarfp
frml(equation=standard,vector=phi1) phi1f
frml(equation=transit,vector=phi2) phi2f
nlls(parmset=regparms,frml=star) x
nlls(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-Newton
Convergence in     2 Iterations. Final criterion was  0.0000000 <=  0.0000100
Dependent Variable X
Monthly Data From 1983:10 To 2012:02
Usable Observations                       247
Degrees of Freedom                        243
Skipped/Missing (from 341)                 94
Centered R^2                        0.5534989
R-Bar^2                             0.5479865
Uncentered R^2                      0.5577255
Mean of Dependent Variable       0.0038656906
Std Error of Dependent Variable  0.0396237788
Standard Error of Estimate       0.0266398383
Sum of Squared Residuals         0.1724524788
Regression F(3,243)                  100.4105
Significance Level of F             0.0000000
Log Likelihood                       546.9994
Durbin-Watson Statistic                1.8618

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
1.  PHI1(1)                      -0.028798399  0.013261227     -2.17162  0.03085184
2.  PHI1(2)                       0.820885467  0.304180237      2.69868  0.00744989
3.  PHI2(1)                       0.054613510  0.027809333      1.96386  0.05068694
4.  PHI2(2)                      -0.274816519  0.212242526     -1.29482  0.19661021

Nonlinear Least Squares - Estimation by Gauss-Newton
NO CONVERGENCE IN 100 ITERATIONS
LAST CRITERION WAS  0.0061040
Dependent Variable X
Monthly Data From 1983:10 To 2012:02
Usable Observations                       247
Degrees of Freedom                        241
Skipped/Missing (from 341)                 94
Centered R^2                        0.5571299
R-Bar^2                             0.5479417
Uncentered R^2                      0.5613222
Mean of Dependent Variable       0.0038656906
Std Error of Dependent Variable  0.0396237788
Standard Error of Estimate       0.0266411589
Sum of Squared Residuals         0.1710500752
Log Likelihood                       548.0078
Durbin-Watson Statistic                1.8646

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
1.  PHI1(1)                         -2.031226   128.525521     -0.01580  0.98740378
2.  PHI1(2)                        -16.771337  1112.602706     -0.01507  0.98798564
3.  PHI2(1)                          2.091723   128.696939      0.01625  0.98704593
4.  PHI2(2)                         17.160119  1111.810132      0.01543  0.98769839
5.  GAMMA                            0.956851     1.831588      0.52242  0.60186028
6.  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

Re: LSTR with exogenous variables

Posted: Fri Apr 06, 2012 5:56 pm
by TomDoan
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 = zarr
stats x
compute scalef=1.0/sqrt(%variance)
*
nonlin(parmset=starparms) gamma c
frml flstar = %logistic(scalef*gamma*(zarfp-c),1.0)
compute c=%mean,gamma=2
equation standard x
#constant zarfp
equation transit x
#constant zarfp
*
frml(equation=standard,vector=phi1) phi1f
frml(equation=transit,vector=phi2) phi2f
frml star x = f=flstar,phi1f+f*phi2f
*
nonlin(parmset=regparms) phi1 phi2
nonlin(parmset=constraints) phi2(1)=-phi1(1) phi2(2)=1-phi1(2)
nonlin(parmset=starparms) gamma c
nlls(parmet=regparms,frml=star) x
*
equation standard x
#constant zarfp
equation transit x
#constant zarfp
frml(equation=standard,vector=phi1) phi1f
frml(equation=transit,vector=phi2) phi2f
nlls(parmset=regparms,frml=star) x
nlls(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-Newton
Convergence in     2 Iterations. Final criterion was  0.0000000 <=  0.0000100
Dependent Variable X
Monthly Data From 1983:10 To 2012:02
Usable Observations                       247
Degrees of Freedom                        243
Skipped/Missing (from 341)                 94
Centered R^2                        0.5534989
R-Bar^2                             0.5479865
Uncentered R^2                      0.5577255
Mean of Dependent Variable       0.0038656906
Std Error of Dependent Variable  0.0396237788
Standard Error of Estimate       0.0266398383
Sum of Squared Residuals         0.1724524788
Regression F(3,243)                  100.4105
Significance Level of F             0.0000000
Log Likelihood                       546.9994
Durbin-Watson Statistic                1.8618

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
1.  PHI1(1)                      -0.028798399  0.013261227     -2.17162  0.03085184
2.  PHI1(2)                       0.820885467  0.304180237      2.69868  0.00744989
3.  PHI2(1)                       0.054613510  0.027809333      1.96386  0.05068694
4.  PHI2(2)                      -0.274816519  0.212242526     -1.29482  0.19661021

Nonlinear Least Squares - Estimation by Gauss-Newton
NO CONVERGENCE IN 100 ITERATIONS
LAST CRITERION WAS  0.0061040
Dependent Variable X
Monthly Data From 1983:10 To 2012:02
Usable Observations                       247
Degrees of Freedom                        241
Skipped/Missing (from 341)                 94
Centered R^2                        0.5571299
R-Bar^2                             0.5479417
Uncentered R^2                      0.5613222
Mean of Dependent Variable       0.0038656906
Std Error of Dependent Variable  0.0396237788
Standard Error of Estimate       0.0266411589
Sum of Squared Residuals         0.1710500752
Log Likelihood                       548.0078
Durbin-Watson Statistic                1.8646

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
1.  PHI1(1)                         -2.031226   128.525521     -0.01580  0.98740378
2.  PHI1(2)                        -16.771337  1112.602706     -0.01507  0.98798564
3.  PHI2(1)                          2.091723   128.696939      0.01625  0.98704593
4.  PHI2(2)                         17.160119  1111.810132      0.01543  0.98769839
5.  GAMMA                            0.956851     1.831588      0.52242  0.60186028
6.  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?

Re: LSTR with exogenous variables

Posted: Fri Apr 06, 2012 6:42 pm
by Ana_Rita
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

Re: LSTR with exogenous variables

Posted: Sat Apr 07, 2012 11:39 am
by Ana_Rita
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!...

Re: LSTR with exogenous variables

Posted: Wed Apr 11, 2012 10:28 am
by Ana_Rita
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

Re: LSTR with exogenous variables

Posted: Wed Apr 11, 2012 12:46 pm
by TomDoan
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.xls
data(format=xls,org=columns) 1 250 entry y
graph(footer="Figure 7.10 The Simulated LSTAR Process")
# y
*
stats y
@bjident y
linreg 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 c
linreg y
# constant y{1}
frml(vector=phi1,lastreg) phi1f
frml(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 y
compute c=%mean
compute 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) y
compute grid=%seqa(%fract01,(%fract99-%fract01)/99.0,100)
dec real cgrid
compute minrss=1.e+100
nonlin(parmset=starparms) gamma c=cgrid
dofor cgrid = grid
   nlls(frml=star,parmset=regparms+starparms,noprint) y
   if %rss<minrss
      compute minrss=%rss,cbest=cgrid
   disp c %rss
end dofor cgrid
*
compute c=cbest
nonlin(parmset=starparms) gamma c
nlls(frml=star,parmset=regparms+starparms,print) y
lstar.xls
Data file
(14.46 KiB) Downloaded 998 times

Re: LSTR with exogenous variables

Posted: Wed Apr 11, 2012 1:53 pm
by Ana_Rita
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

Re: LSTR with exogenous variables

Posted: Wed Apr 11, 2012 2:45 pm
by TomDoan
If you post your data and the program you're trying to run, I'll take a look at it.

Re: LSTR with exogenous variables

Posted: Wed Apr 11, 2012 4:49 pm
by Ana_Rita
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...

Re: LSTR with exogenous variables

Posted: Wed Apr 11, 2012 9:40 pm
by TomDoan
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.

Re: LSTR with exogenous variables

Posted: Thu Apr 12, 2012 7:17 pm
by Ana_Rita
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

Re: LSTR with exogenous variables

Posted: Thu Apr 12, 2012 9:54 pm
by TomDoan
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.

Re: LSTR with exogenous variables

Posted: Fri Apr 13, 2012 7:53 am
by Ana_Rita
Is that hinting at the use of a SETAR model instead, given the "step" transition?