Switching model workbook, example 9.3

Discussion of models with structural breaks or endogenous switching.
n141
Posts: 11
Joined: Mon Dec 05, 2016 8:47 pm

Switching model workbook, example 9.3

Unread post by n141 »

Dear Tom Doan,

Is it possible to use the nfix option in example 9.3 of the workbook? This example estimates a Markov switching autoregressive model using Bayesian MCMC. If so, can you please indicate where the changes are required?

Best regards.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Switching model workbook, example 9.3

Unread post by TomDoan »

You can. This is designed for handling a situation where the regimes are "independent" (no common coefficients, no common variance):
do i=1,nstates
      cmom(smpl=(MSRegime==i),equation=MSRegEqn) gstart gend
      compute betas(i)=%ranmvpostcmom($
         %cmom,1.0/sigsqv(i),hprior,bprior)
      if %MSRegARIsUnstable(%xsubvec(betas(i),2,3))
         goto redrawbeta
   end do i
so it just does separate samples on the data from each regime. If you have common coefficients, you need to sample the entire set of regression coefficients together. That's a regression of the form
switchingreg.png
switchingreg.png (1.35 KiB) Viewed 51319 times
which would have to be done using weighted least squares to allow for the regime-specific variances. Alternatively, you can do the fixed and regime-specific coefficients in different blocks. That will involve subtracting off the fixed coefficient part from the dependent variable in doing the regime-specific draws above, and adding a separate draw of weighted-least squares on the dependent variable minus the regime-specific part to get a draw for the fixed coefficients. (That's what is done in the EM algorithm).
switchingregblocks.png
switchingregblocks.png (3.66 KiB) Viewed 51319 times
n141
Posts: 11
Joined: Mon Dec 05, 2016 8:47 pm

Re: Switching model workbook, example 9.3

Unread post by n141 »

Dear Tom Doan,

Thank you for the suggestion. Can you please help me with the code for this section?

Best regards.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Switching model workbook, example 9.3

Unread post by TomDoan »

Sure. Show me what you have.
n141
Posts: 11
Joined: Mon Dec 05, 2016 8:47 pm

Re: Switching model workbook, example 9.3

Unread post by n141 »

Dear Tom Doan,

Sorry for replying late. I am a new RATS user and it is taking a while to figure it out. Since you pointed towards EM algorithm and it is a Bayesian MCMC, can the code be like the following:

Code: Select all

if MSRegNSwitch>0 {
   @MSRegFixResids MSRegU gstart gend
   do i=1,nstates
      set wt gstart gend = qhat=MSEMMarginal(MSEMpt_sm(t)),qhat(i)
      cmom(smpl=(MSRegime==i),weight=wt,equation=MSRegEqnSwitch,depvar) gstart gend
      compute betas(i)=%ranmvpostcmom(%cmom,1.0/sigsqv(i),hprior,bprior)   
   end do i
}
*
if MSRegNFix>0 {
   compute cmomEM=%zeros(MSRegNFix+1,MSRegNFix+1)
   do i=1,nstates
      gset iregime gstart gend = i
      @MSRegSwitchResids(regime=iregime) MSRegU gstart gend
      set wt gstart gend = qhat=MSEMMarginal(MSEMpt_sm(t)),qhat(i)
      cmom(weight=wt,spread=sigsqv(i),equation=MSRegEqnFix,depvar) gstart gend
      compute cmomEM=cmomEM+%cmom
   end do i
   compute gammas=%ranmvpostcmom(%cmom,1.0/sigsqv(i),hprior,bprior)   
}
Best regards.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Switching model workbook, example 9.3

Unread post by TomDoan »

Close. One thing to note is that there needs to be a separate prior mean and precision for each of the N+1 regressions. The switch regressions are all the same size, and you can use a common prior for all of those if you're not trying to make the regime "labeling" depend upon the behavior of those. (If, say, the hope is that the regimes switch based upon variance instead). The fixed regression is a completely different size and so will need its own prior.

The main difference between EM and the corresponding Gibbs sampler is that EM probabilistically weights the regimes, while the Gibbs sampler treats them as "known" (at the currently sampled values). So you need to get rid of the wt series and rely only on the SMPL options. And in drawing the gammas, you've already taken into account the sigma's when forming the cross product matrix, so you use 1.0 as the equation precision:

compute gammas=%ranmvpostcmom(%cmom,1.0,hprior(needs to change),bprior(needs to change))
n141
Posts: 11
Joined: Mon Dec 05, 2016 8:47 pm

Re: Switching model workbook, example 9.3

Unread post by n141 »

Dear Tom Doan,

Would regime dependent time trend make any sense in the Markov switching specification?

Best regards.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Switching model workbook, example 9.3

Unread post by TomDoan »

Lam's model has a regime-dependent trend rate. However, it's quite a bit more complicated than even the (related) Hamilton model. I'm not sure how one would do a regime-dependent trend directly since the different trends would separate too much as you got later into the entry range.

LAM, P.-S. (1990): “The Hamilton model with a general autoregressive component: estimation and comparison with other models of economic time series", Journal of Monetary Economics, 26(3), 409–432.
gabri_london
Posts: 4
Joined: Mon Aug 07, 2017 3:16 am

Re: Switching model workbook, example 9.3

Unread post by gabri_london »

Dear Tom,
I have worked in the past with ARCH, SWARCH and MSVAR models. In the UG manual (version 8 page 365) I read that is not possible to combine MS specification of the mean M ( Hamilton type model) state dependent models with MS specification of the "I" intercept state dependent model. However, I noticed that the specification switch = , the mh (mean variance) is among the allowed ones. To this regard, I have the following questions:
Would it be possible to combine a MSAR (univariate) model (or MSregression) with a Switching variance model? If so, could you please kindly provide references?
Would it be possible to combine MSAR (or MSregression) with an ARCH/GARCH specification?
And for sake of completeness, would it be possible to combine MSAR (or MSregression) with SWARCH?
Thank you in advance for your attention and help.
Gabriella
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Switching model workbook, example 9.3

Unread post by TomDoan »

gabri_london wrote:Dear Tom,
I have worked in the past with ARCH, SWARCH and MSVAR models. In the UG manual (version 8 page 365) I read that is not possible to combine MS specification of the mean M ( Hamilton type model) state dependent models with MS specification of the "I" intercept state dependent model. However, I noticed that the specification switch = , the mh (mean variance) is among the allowed ones. To this regard, I have the following questions:
Would it be possible to combine a MSAR (univariate) model (or MSregression) with a Switching variance model? If so, could you please kindly provide references?
I'm not sure what you mean. @MSRegression has the SWITCH=[C]/CH/H option. @MSVARSETUP (for MS-AR's) also allows for switching variances in all the mean model switches.
gabri_london wrote: Would it be possible to combine MSAR (or MSregression) with an ARCH/GARCH specification?
You can. It's not simple, because even if the GARCH process is fixed, the dependence of the variance on past regimes through the residuals doesn't have a finite cutoff.
gabri_london wrote: And for sake of completeness, would it be possible to combine MSAR (or MSregression) with SWARCH?
Yes.
gabri_london
Posts: 4
Joined: Mon Aug 07, 2017 3:16 am

Re: Switching model workbook, example 9.3

Unread post by gabri_london »

Thank you Tom, very much appreciated.
Gabriella
Post Reply