* * Martin, Hurn, Harris, "Econometric Modelling with Time Series" * Example 19.9, from pp 737-8 * Markov Switching Model of the Business Cycle * open data gnp.dat cal(q) 1951:1 data(format=free,org=var) 1951:01 1984:4 gnp * set ggrow = 100.0*log(gnp/gnp{1}) * * The simplest way to set this up is with @MSVARSETUP with LAGS=0. SWITCH=MH * switches the mean and the variance. * @msvarsetup(lags=0,switch=mh) # ggrow compute gstart=1951:2,gend=1984:4 frml msvarf = log(%MSVARProb(t)) * * The RATS M-S routines use a different way to represent the parameters than is * used in the text. Instead of p and q, it uses the top row of the transition * matrix. Instead of base + differential, it estimates separate mean and variance * in each regime. The information is equivalent, just in a different form. * * The regimes are also set up to have the lower mean first. * nonlin(parmset=msparms) p nonlin(parmset=varparms) mu phi sigmav @msvarinitial gstart gend * * Estimate the model by maximum likelihood. * maximize(parmset=varparms+msparms,\$ start=(pstar=%MSVARInit()),\$ reject=%MSVARInitTransition()==0.0,\$ pmethod=simplex,piters=5,method=bfgs,iters=300) msvarf gstart gend * * Compute the durations from the transition probabilities * summarize(parmset=varparms+msparms,title="Duration(expansion)") 1.0/p(1,2) summarize(parmset=varparms+msparms,title="Duration(contraction)") 1.0/(1-p(1,1))