Estimation of LSTAR models

Discussion of models with structural breaks or endogenous switching.
AndreRiver
Posts: 6
Joined: Mon Oct 29, 2018 7:51 pm

Estimation of LSTAR models

Unread post by AndreRiver »

Dear all,
I am trying to estimate a lstar model (I am attaching the data) using the code:

Code: Select all

calendar(q) 1981:1
allocate 2015:4
open data
data(format=xls,org=obs)
print
nonlin a0 b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 b16 gamma c
frml glstar = %logistic(gamma*(u{5}-c),1.0)
frml lstar u= g=glstar,a0+(b1*u{1}+b2*u{2}+b3*u{3}+b4*u{4}+b5*u{5}+b6*u{6}+b7*u{7}+b8*u{8})*(1-g)+(b9*u{1}+b10*u{2}+b11*u{3}+b12*u{4}+b13*u{5}+b14*u{6}+b15*u{7}+b16*u{8})*g
stats(fractiles) u
compute ygrid=%seqa(%fract05,(%fract75-%fract25)/49,50)
compute ggrid=%exp(%seqa(log(.25),.1*log(10),8))/(%fract75-%fract25)
nonlin a0 b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 b16 
compute bestrss=%na
dofor c = ygrid
dofor gamma = ggrid
nlls(noprint,frml=lstar) u 1982:3 2015:4
if .not.%valid(bestrss).or.%rss<bestrss
compute bestrss=%rss,bestc=c,bestgamma=gamma
end dofor gamma
end dofor c
disp "Guess values used" bestc "and" bestgamma
compute c=bestc,gamma=bestgamma
nonlin a0 b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 b16 gamma c
nlls(frml=lstar) u 1982:3 2015:4
However, I am getting some problems like:
The Error Occurred At Location 168, Line 3 of loop/block
## NL6. NONLIN Parameter A0 Has Not Been Initialized. Trying 0
The Error Occurred At Location 168, Line 3 of loop/block
## NL6. NONLIN Parameter B1 Has Not Been Initialized. Trying 0
The Error Occurred At Location 168, Line 3 of loop/block
## NL6. NONLIN Parameter B2 Has Not Been Initialized. Trying 0
The Error Occurred At Location 168, Line 3 of loop/block
## NL6. NONLIN Parameter B3 Has Not Been Initialized. Trying 0
The Error Occurred At Location 168, Line 3 of loop/block
## NL6. NONLIN Parameter B4 Has Not Been Initialized. Trying 0
The Error Occurred At Location 168, Line 3 of loop/block
## NL6. NONLIN Parameter B5 Has Not Been Initialized. Trying 0
The Error Occurred At Location 168, Line 3 of loop/block
## NL6. NONLIN Parameter B6 Has Not Been Initialized. Trying 0
The Error Occurred At Location 168, Line 3 of loop/block
## NL6. NONLIN Parameter B7 Has Not Been Initialized. Trying 0
The Error Occurred At Location 168, Line 3 of loop/block
## NL6. NONLIN Parameter B8 Has Not Been Initialized. Trying 0
The Error Occurred At Location 168, Line 3 of loop/block
## NL6. NONLIN Parameter B9 Has Not Been Initialized. Trying 0
The Error Occurred At Location 168, Line 3 of loop/block
## NL6. NONLIN Parameter B10 Has Not Been Initialized. Trying 0
The Error Occurred At Location 168, Line 3 of loop/block
## NL6. NONLIN Parameter B11 Has Not Been Initialized. Trying 0
The Error Occurred At Location 168, Line 3 of loop/block
## NL6. NONLIN Parameter B12 Has Not Been Initialized. Trying 0
The Error Occurred At Location 168, Line 3 of loop/block
## NL6. NONLIN Parameter B13 Has Not Been Initialized. Trying 0
The Error Occurred At Location 168, Line 3 of loop/block
## NL6. NONLIN Parameter B14 Has Not Been Initialized. Trying 0
The Error Occurred At Location 168, Line 3 of loop/block
## NL6. NONLIN Parameter B15 Has Not Been Initialized. Trying 0
The Error Occurred At Location 168, Line 3 of loop/block
## NL6. NONLIN Parameter B16 Has Not Been Initialized. Trying 0

Can anyone tell me what is wrong with my code? Also, as you can note the model has two autoregressive parts. Is there any manner to introduce in the code some way to estimate the optimal lag length according to some info criterion?

Best,
Andrea.
Attachments
bra.xls
(30.5 KiB) Downloaded 1219 times
TomDoan
Posts: 7776
Joined: Wed Nov 01, 2006 4:36 pm

Re: Estimation of LSTAR models

Unread post by TomDoan »

There's nothing wrong with the code---those are warnings, and 0 is a perfectly reasonable guess value for those under the circumstances.

Have you read the section in the User's Guide on STAR Models?
AndreRiver
Posts: 6
Joined: Mon Oct 29, 2018 7:51 pm

Re: Estimation of LSTAR models

Unread post by AndreRiver »

Thanks for the clarification. I checked the guide and it was very helpful. Thanks much!
AndreRiver
Posts: 6
Joined: Mon Oct 29, 2018 7:51 pm

Re: Estimation of LSTAR models

Unread post by AndreRiver »

TomDoan wrote:Have you read the section in the User's Guide on STAR Models?
Tom: checking the guide and comparing with the programming manual (as well as some books) there is a slight modification of the lstar function present in the guide. Why is that? Does it mean that if I use the %logistic function this apply the lstar specification present in the guide? Thanks!

Andrea
TomDoan
Posts: 7776
Joined: Wed Nov 01, 2006 4:36 pm

Re: Estimation of LSTAR models

Unread post by TomDoan »

The point of the %logistic is to avoid numerical problems---it's the standard logistic function, but computed in an overflow-safe fashion. There are several equivalent ways to write transition models, so I'm not sure what you mean by a "slight modification."

One thing to note is that you have a single intercept rather than making that regime-dependent. If the u's aren't mean zero, that's probably a bad idea.
AndreRiver
Posts: 6
Joined: Mon Oct 29, 2018 7:51 pm

Re: Estimation of LSTAR models

Unread post by AndreRiver »

Thanks again for the clarification.
TomDoan wrote:One thing to note is that you have a single intercept rather than making that regime-dependent. If the u's aren't mean zero, that's probably a bad idea.
Tom: I am intrigued by your comment about the intercept. Could you please tell me more about it or suggest me a reference to know more about how this is a bad idea?

Thanks!

Andrea
TomDoan
Posts: 7776
Joined: Wed Nov 01, 2006 4:36 pm

Re: Estimation of LSTAR models

Unread post by TomDoan »

You would expect the mean of the residual to be zero in each regime. If you have a single intercept, how can that happen?
AndreRiver
Posts: 6
Joined: Mon Oct 29, 2018 7:51 pm

Re: Estimation of LSTAR models

Unread post by AndreRiver »

Tom: Thank you! I modified my code to include two constant terms (one for each regime) but I am getting the result: ## SR10. Missing Values And/Or SMPL Options Leave No Usable Data Points

I get this outcome even though I shrink my sample.

Code: Select all

calendar(q) 1981:1
allocate 2015:4
open data
data(format=xls,org=obs)
print
compute scalef=1.0/sqrt(%variance)
nonlin a0 a1 b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 gamma c
frml glstar = %logistic(scalef*gamma*(u{5}-c),1.0)
frml lstar u= g=glstar,(a0+b1*u{1}+b2*u{2}+b3*u{3}+b4*u{4}+b5*u{5}+b6*u{6})*(1-g)+(a1+b7*u{1}+b8*u{2}+b9*u{3}+b10*u{4}+b11*u{5}+b12*u{6})*g
compute ygrid=%seqa(%fract05,(%fract75-%fract25)/49,50)
compute ggrid=%exp(%seqa(log(.25),.1*log(10),8))/(%fract75-%fract25)
nonlin a0 a1 b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12  
compute bestrss=%na
dofor c = ygrid
dofor gamma = ggrid
nlls(noprint,frml=lstar) u 
if .not.%valid(bestrss).or.%rss<bestrss
compute bestrss=%rss,bestc=c,bestgamma=gamma
end dofor gamma
end dofor c
disp "Guess values used" bestc "and" bestgamma
compute c=bestc,gamma=bestgamma
nonlin a0 a1 b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 gamma c
nlls(frml=lstar) u
TomDoan
Posts: 7776
Joined: Wed Nov 01, 2006 4:36 pm

Re: Estimation of LSTAR models

Unread post by TomDoan »

You're using statistics like %variance and %fractxx without ever doing a STATISTICS instruction to compute them.
AndreRiver
Posts: 6
Joined: Mon Oct 29, 2018 7:51 pm

Re: Estimation of LSTAR models

Unread post by AndreRiver »

Thank you. One more question: Is there any function like %logistic to estimate an exponential model? Or, what would be the best approach in RATS for those kind of exponential models?
TomDoan
Posts: 7776
Joined: Wed Nov 01, 2006 4:36 pm

Re: Estimation of LSTAR models

Unread post by TomDoan »

No. It isn't needed. That's described in the User's Guide.
PedroClavijo
Posts: 9
Joined: Tue Aug 27, 2019 11:51 pm

Estimation of LSTAR models using ML

Unread post by PedroClavijo »

Dear Tom and RATS users,
I have to estimate an LSTAR model. I have used NLLS and now I want to use ML to compare; the code I am employing is the following:

Code: Select all

calendar(a) 1865:1
allocate 2010:1
open data
data(format=xls,org=obs)
*
declare series  ys
declare integer d
*
nonlin(parmset=starparms) gamma mu
frml flstar = (1+exp(-gamma*(ys{d}-mu)))**-1
*
set trend = t
*
set ys = LA
*
compute d=4
*
stats(noprint) ys
compute gamma=2.0/sqrt(%variance)
compute mu=%mean
*
equation parameters ys
# constant trend 
equation standard ys
# ys{1 to 5}
equation transit ys
# ys{1 to 5}
*
frml(equation=parameters,vector=para) paraf
frml(equation=standard,vector=phi1) phi1f
frml(equation=transit ,vector=phi2) phi2f
frml star ys = f=flstar,paraf+(1-f)*phi1f+f*phi2f
*
nonlin(parmset=regparms) para phi1 phi2 
nonlin(parmset=starparms) gamma mu
*
nonlin(parmset=varia) var
frml l = %logdensity(var,ys-star)
compute phi1=%const(0.0),phi2=%const(0.0),para=%const(0.0), var=1, gamma=2.0/sqrt(%variance), mu=%mean
*
maximize(parmset=regparms+starparms+varia,iterations=200,method=simplex) l
maximize(parmset=regparms+starparms+varia,iterations=200,robusterrors) l
I actually could estimate the model without any problem, all I want is to know if the code looks fine and get any suggestion to improve the estimation.
Thanks!
TomDoan
Posts: 7776
Joined: Wed Nov 01, 2006 4:36 pm

Re: Estimation of LSTAR models

Unread post by TomDoan »

NLLS is maximum likelihood for that model---there's no reason to go to the extra work. (NLLS is also numerically better-behaved and has a cleaner estimate of the covariance matrix).
PedroClavijo
Posts: 9
Joined: Tue Aug 27, 2019 11:51 pm

Re: Estimation of LSTAR models

Unread post by PedroClavijo »

Dear Tom.
Eitrheim and Teräsvirta (1996) in "Testing the adequacy of smooth transition autoregressive models" (Journal of Econometrics) propose some diagnostic test after estimating an LSTAR model. Is there any code I can use to estimate those test in RATS?

Best,
PC
Post Reply