Page 1 of 1

Markov Switching VECM

PostPosted: Fri Apr 05, 2013 2:52 am
by nacrointfin
Dear All:

Can the markov switching vecm be implemented under the command 'msvarsetup'?

Best,

Terence Wan

Re: Markov Switching VECM

PostPosted: Fri Apr 05, 2013 10:36 am
by TomDoan
nacrointfin wrote:Dear All:

Can the markov switching vecm be implemented under the command 'msvarsetup'?

Best,

Terence Wan


You would have to use @MSSysRegression instead since it allows for more general equation forms. The one difference is that MSVARSETUP allows for switching means, while MSSysRegression only has switching coefficients.

Re: Markov Switching VECM

PostPosted: Tue Apr 09, 2013 8:08 pm
by nacrointfin
Dear Tom

Is there any markov switching VECM example using command @MSSysRegression ?

Best,

Terence Wan

Re: Markov Switching VECM

PostPosted: Tue Apr 09, 2013 8:18 pm
by TomDoan
This has some extra calculations, but does shows the general idea. You estimate the cointegrating vector by standard methods then input the error correction term as an explanatory variable.

Code: Select all
open data data.xls
calendar(q) 1955
all 2006:01
data(format=xls,org=columns) 1955:01 2006:01 cgbv cgce bcaj dydc royj bcje
*
* Patch over missing values in BCAJ, which is quarterly for part of the range.
*
dec rect a(2,2)
compute a=||2.0,-1.0|1.0,0.0||
compute c=||1.0,0.0||
dlm(type=smooth,sw=%diag(||1.0,0.0||),a=a,c=c,exact,y=bcaj) 1959:2 * xstates
set bcaj 1959:2 * = xstates(t)(1)
*
set le  = log(royj/bcaj)
set lp  = log(cgbv)
set lwp = le-lp
set lns = log(dydc/(1-.01*bcje))
set ly  = log(cgce)
set ln  = log(dydc)
*
graph
# ly 1965:1 2001:1
graph
# lwp 1965:1 2001:1
*
source johmle.src
@johmle(determ=rtrend,lags=4,eigval=eigval) 1966:2 2001:1
# ly lwp ln lns
*
compute [symm] s10_00_01=tr(%%s01)*inv(%%s00)*%%s01
dec rect d(5,3)
input d
   0.0    1.0    0.0
   0.0    0.0    1.0
   1.0    0.0    0.0
  -1.0    0.0    0.0
   0.0  -.0056 -.0048
eigen(general=%mqform(%%s11,d)) %mqform(s10_00_01,d) eigvalr eigvecr
*
* LR test of restriction given 1 cointegrating relation
*
compute lr=%nobs*log(1-eigvalr(1))-%nobs*log(1-eigval(1))
cdf chisqr lr 2
*
compute [vect] x1r=d*%xcol(eigvecr,1)
compute x1r=x1r/x1r(4)
disp "Restricted cointegrating vector"
disp x1r
*
* Error correction series
*
set eqm = %dot(x1r,||ly,lwp,ln,lns,t||)
diff(center) eqm 1965:2 2001:1
*
set dly  = 100.0*(ly-ly{1})
set dlwp = 100.0*(lwp-lwp{1})
set dlns = 100.0*(lns-lns{1})
set dln  = 100.0*(ln-ln{1})
*
@mssysregression(states=2,switch=ch,nfix=8)
# dly dlwp dlns dln
# dly{1 2} dlwp{1 2} dlns{1 2} dln{1 2} constant eqm
*
compute gstart=1965:4,gend=2001:1
*
nonlin(parmset=msparms)  p
nonlin(parmset=vecmparms) sigmav gamma beta
@MSSysRegInitial gstart gend
*
* Reset beta(2) to zero loadings on the cointegrating vector
*
compute beta(2)(2,1)=beta(2)(2,2)=beta(2)(2,3)=beta(2)(2,4)=0.0
*compute sigmav(2)=sigmav(1)*2.0
@MSSysRegEMGeneralSetup
do emits=1,50
   @MSSysRegEMStep gstart gend
   disp "Iteration" emits "Log likelihood" %logl
end do emits
compute p=%xsubmat(p,1,nstates-1,1,nstates)
frml logl = f=%MSSysRegFVec(t),pt_t1=%mcstate(p,pstar),$
  pt_t=pstar=%msupdate(f,pt_t1,fpt),log(fpt)
maximize(start=(pstar=%MSSysRegInit()),parmset=vecmparms,$
  method=bfgs) logl gstart gend