MS-ARIMA

Discussion of models with structural breaks or endogenous switching.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: MS-ARIMA

Unread post by TomDoan »

compute x0=||5.224,2.699||
*********************************************************************
gset xstates = %zeros(ndlm,1)
compute DLMStart()
@MSFilterInit

1. x0 is the wrong dimension. I'm not sure where you're getting the two values you have, but it's supposed to be length 5 since it's the pre-sample state vector.

2. Add the compute DLMStart() line to transfer initial information before doing the @MSFilterInit.
fan
Posts: 215
Joined: Wed Jun 19, 2013 5:14 pm

Re: MS-ARIMA

Unread post by fan »

TomDoan wrote:compute x0=||5.224,2.699||
*********************************************************************
gset xstates = %zeros(ndlm,1)
compute DLMStart()
@MSFilterInit

1. x0 is the wrong dimension. I'm not sure where you're getting the two values you have, but it's supposed to be length 5 since it's the pre-sample state vector.

2. Add the compute DLMStart() line to transfer initial information before doing the @MSFilterInit.
Hi Tom, Thank you very much for the reply. Could you please let me know where I should modify the above code to allow for time varying probabilities?
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: MS-ARIMA

Unread post by TomDoan »

This treats P as a fixed matrix. You would have to compute P as a function of the function argument <<time>> instead.

compute likely=0.0
do i=1,nstates
do j=1,nstates
compute phat(i,j)=p(i,j)*pstar(j)*fwork(i,j)
compute likely=likely+phat(i,j)
end do j
end do i
fan
Posts: 215
Joined: Wed Jun 19, 2013 5:14 pm

Re: MS-ARIMA

Unread post by fan »

TomDoan wrote:This treats P as a fixed matrix. You would have to compute P as a function of the function argument <<time>> instead.

compute likely=0.0
do i=1,nstates
do j=1,nstates
compute phat(i,j)=p(i,j)*pstar(j)*fwork(i,j)
compute likely=likely+phat(i,j)
end do j
end do i
hi Tom, thank you for the quick reply. i tried to modify the codes to allow P as a function of the function argument <<time>>. unfortunately, the modification did not work. Error messages appear like
Can't Find Match for %MSPROB(INTEGER). Closest Match is %MSPROB(INTEGER,VECTOR[REAL])
## SX27. Illegal Combination of Data Types for Operation
>>>>t(t),log(%MSProb(t)<<<<

i am not sure the cause of the errors. Could you please kindly take a look my attached code and help me find out the errors? Many Thanks
Attachments
arma-tvp.RPF
(5.94 KiB) Downloaded 1223 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: MS-ARIMA

Unread post by TomDoan »

%MSPROB isn't computing the likelihood---KimFilter is---so get rid of that FRML instruction that's causing the error. You also have to compute the P matrix inside KimFilter with

compute p=%MSPMat(time)

before you reach the loop that uses it.
fan
Posts: 215
Joined: Wed Jun 19, 2013 5:14 pm

Re: MS-ARIMA

Unread post by fan »

TomDoan wrote:%MSPROB isn't computing the likelihood---KimFilter is---so get rid of that FRML instruction that's causing the error. You also have to compute the P matrix inside KimFilter with

compute p=%MSPMat(time)

before you reach the loop that uses it.
Hi Tom. thank you for the quick reply. Following your advise,I took off the FRML instruction for %MSPROB and add compute p=%MSPMat(time) before running the Hamilton filter. However, I am still having following error messages

The Error Occurred At Location 170, Line 13 of %MSINIT
Called From Location 127, Line 13 of MSFILTERINIT
## MAT14. Non-invertible Matrix. Using Generalized Inverse for SYMMETRIC.
## MAT2. Matrices with Dimensions 2 x 1 and 2 x 2 Involved in * Operation
The Error Occurred At Location 268, Line 16 of %MSPMAT
Called From Location 552, Line 39 of KIMFILTER

I see that i need to replace the original code

Code: Select all

 compute p=%msexpand(p), compute pstar=%mcergodic
with

Code: Select all

 p=%mspmat(time), compute pstar=||%logistic(v1(1),1.0),1-%logistic(v2(1),1.0)|| 
by using function %MSPmat time and function TVPInit individually to allow probabilities to vary with time. However, I am not clear about the causes of the errors. Could you please kindly a take look at the attached code and share your thoughts with me? Thank you
Attachments
arma-tvp.RPF
(5.84 KiB) Downloaded 1182 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: MS-ARIMA

Unread post by TomDoan »

Your P matrix is a global that's dimensioned 2 x 2, but in %MSPMAT you only use it as a 1 x 2. Use a local RECT in that function rather than P.
fan
Posts: 215
Joined: Wed Jun 19, 2013 5:14 pm

Re: MS-ARIMA

Unread post by fan »

TomDoan wrote:Your P matrix is a global that's dimensioned 2 x 2, but in %MSPMAT you only use it as a 1 x 2. Use a local RECT in that function rather than P.
Hi Tom, I am sorry to ask question again. I made relevant changes to the code following your suggestions. However, new error messages say “## MAT13. Store into Out-of-Range Matrix or Series Element; The Error Occurred At Location 9, Line 10 of %MSPMAT; Called From Location 99, Line 19 of DLMSTART”. I do not quite understand the messages. Could you please help me understand where the errors occurred in my code?
Attachments
arma-tvp(new).RPF
(5.84 KiB) Downloaded 1177 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: MS-ARIMA

Unread post by TomDoan »

It's pointing you to line 10 (the compute below) and telling you that you're storing into an out-of-range element. That's P. Where is P dimensioned? Now that it's local, nowhere. You need

local rect p(1,2)

Code: Select all

local rect    p
*
compute p(1,1)=%(z=exp(%dot(%eqnxvector(p1eq,time),v1)),z/(1+z))
compute p(1,2)=%(z=exp(%dot(%eqnxvector(p2eq,time),v2)),1/(1+z))
fan
Posts: 215
Joined: Wed Jun 19, 2013 5:14 pm

Re: MS-ARIMA

Unread post by fan »

TomDoan wrote:It's pointing you to line 10 (the compute below) and telling you that you're storing into an out-of-range element. That's P. Where is P dimensioned? Now that it's local, nowhere. You need

local rect p(1,2)

Code: Select all

local rect    p
*
compute p(1,1)=%(z=exp(%dot(%eqnxvector(p1eq,time),v1)),z/(1+z))
compute p(1,2)=%(z=exp(%dot(%eqnxvector(p2eq,time),v2)),1/(1+z))
Thank you, Tom. finally, it worked. :D
fan
Posts: 215
Joined: Wed Jun 19, 2013 5:14 pm

Re: MS-ARIMA

Unread post by fan »

TomDoan wrote:It's pointing you to line 10 (the compute below) and telling you that you're storing into an out-of-range element. That's P. Where is P dimensioned? Now that it's local, nowhere. You need

local rect p(1,2)

Code: Select all

local rect    p
*
compute p(1,1)=%(z=exp(%dot(%eqnxvector(p1eq,time),v1)),z/(1+z))
compute p(1,2)=%(z=exp(%dot(%eqnxvector(p2eq,time),v2)),1/(1+z))
Dear Tom, sorry for posting questions here again. I am interested in examining the transition probabilities of US economy during different political regimes (democratic vs. republican) and first and second half of a presidency(yr12 vs. yr34). However, there is a convergence issue in my estimation process. I tried what suggested by the program, such as giving different initial values, increasing number of iterations, but nothing worked for me. Could you please kindly help me with the issue?
Attachments
ARMA34(BW-Indsg)tvp.RPF
(6.09 KiB) Downloaded 1101 times
quarterlydata.xlsx
(136.81 KiB) Downloaded 1096 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: MS-ARIMA

Unread post by TomDoan »

Given that it's hard to fit even a non-switching ARMA(3,4) model to the data, the fact that you can't fit a switching model isn't a shock. I told you months ago that a 2,4 model was too much. Now it's a 3,4? Cut that down substantially (you can just peg some of the phi's and tau's to zero) and you'll have a better chance.
fan
Posts: 215
Joined: Wed Jun 19, 2013 5:14 pm

Re: MS-ARIMA

Unread post by fan »

TomDoan wrote:Given that it's hard to fit even a non-switching ARMA(3,4) model to the data, the fact that you can't fit a switching model isn't a shock. I told you months ago that a 2,4 model was too much. Now it's a 3,4? Cut that down substantially (you can just peg some of the phi's and tau's to zero) and you'll have a better chance.
Thank you for your quick reply. Is there any general method available that can help people to choose the model to describe the macroeconomic time series if she/he would like to apply MS model to. I picked up 3,4 based on the information contrition. Authors of the papers I read do not rarely mention the reason why them picked up models for their studies, such as AR(4) is commonly used by researchers to model aggregate output since Hamilton.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: MS-ARIMA

Unread post by TomDoan »

No. However, you can probably bet that less complicated will work better than more complicated. The whole idea (if the idea is correct) is that the dynamics are driven more by the MS model than the static time series representation.
fan
Posts: 215
Joined: Wed Jun 19, 2013 5:14 pm

Re: MS-ARIMA

Unread post by fan »

TomDoan wrote:No. However, you can probably bet that less complicated will work better than more complicated. The whole idea (if the idea is correct) is that the dynamics are driven more by the MS model than the static time series representation.
Thank you for the advice
Post Reply