Page 2 of 4

Re: MS-ARIMA

Posted: Sat Oct 31, 2015 11:52 am
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.

Re: MS-ARIMA

Posted: Mon Nov 09, 2015 3:46 am
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?

Re: MS-ARIMA

Posted: Mon Nov 09, 2015 10:34 am
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

Re: MS-ARIMA

Posted: Tue Nov 10, 2015 1:55 am
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

Re: MS-ARIMA

Posted: Tue Nov 10, 2015 10:22 am
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.

Re: MS-ARIMA

Posted: Wed Nov 11, 2015 2:12 am
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

Re: MS-ARIMA

Posted: Wed Nov 11, 2015 6:28 pm
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.

Re: MS-ARIMA

Posted: Mon Nov 16, 2015 8:28 pm
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?

Re: MS-ARIMA

Posted: Wed Nov 18, 2015 12:55 pm
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))

Re: MS-ARIMA

Posted: Thu Nov 19, 2015 11:33 pm
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

Re: MS-ARIMA

Posted: Wed Dec 09, 2015 4:12 pm
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?

Re: MS-ARIMA

Posted: Wed Dec 09, 2015 5:13 pm
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.

Re: MS-ARIMA

Posted: Thu Dec 10, 2015 4:27 pm
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.

Re: MS-ARIMA

Posted: Thu Dec 10, 2015 5:06 pm
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.

Re: MS-ARIMA

Posted: Thu Dec 10, 2015 9:30 pm
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