RATS 11
RATS 11

Procedures /

MSVARSETUP Procedures

Home Page

← Previous Next →

@MSVARSetup is specifically designed to handle a Markov Switching VAR (or univariate autoregression). What's special to this (versus @MSSysRegression for systems of more than one equation or @MSRegression for a single equation) is that you can do a switching process mean. That's only possible if the model has just the lagged dependent variables and CONSTANT as the explanatory variables. If you need any exogenous variables or other deterministic variables, use one of the other procedures.

 

On the regression coefficients, you can have the mean switch, the intercept only or all coefficients. A mean switch causes immediate changes in the process, while an intercept switch creates a more gradual change. Note that if the mean switches, the likelihood function depends upon current and p lags of the M regimes, so there will be \({M^{p + 1}}\) branches. This can get quite large quite fast if the number of lags increases, which slows down the estimation quite a bit.

 

 

@MSVARSetup( options )

# list of dependent variables

Options

REGIMES=number of regimes[2]

Sets the number of regimes. (The older STATES option can be used instead, though REGIMES is preferred).

 

LAGS=number of lags[1]

Sets the number of lags. The VAR is set up with each equation having a CONSTANT and the lags of the dependent variables.
 

SWITCH=[M]/I/MH/IH/C/CH

This determines what switches among regimes. With SWITCH=M, the means switch, and the lag coefficients and covariance matrices are fixed. With SWITCH=I, the intercepts switch, the lag coefficients and covariance matrices are fixed. With SWITCH=MH, the means and covariance matrices switch and the lag coefficients are fixed. With SWITCH=IH, the intercepts and covariance matrices switch and the lag coefficients are fixed. SWITCH=C has all coefficients (intercept and lag coefficients) switching, but the covariance matrices fixed. SWITCH=CH has all coefficients and the covariances matrices switching.

Variables Defined

Everything defined by @MSSetup is also defined by @MSVARSetup, which includes it. These are the variables defined specifically by @MSVARSetup, for use in parameter sets for estimation. Not all of them will be in active use in a particular model. In particular, only one of SIGSQ and SIGSQV will be used in a model; the first for a fixed variance, the second for regime-switching variances and only one of PHI and PHIV (the first if you use M or I switching and the latter if you use C switching).


 

MSVARMODEL

MODEL with the reduced form for the estimated model.

MU

VECTOR[VECTOR] of means/intercepts. MU(s) is the mean/intercept vector at state s.

PHI

VECTOR[RECT] of lag coefficients if the lag coefficients are fixed across regimes. PHI(k) is the \(n \times n\) matrix of coefficients for lag k.

PHIV

RECT[RECT] of lag coefficients if the lag coefficients switch across regimes. PHIV(s,k) is the \(n \times n\) matrix of coefficients for lag k at regime s.

SIGMA

covariance matrix of residuals if the variance isn't switching (SYMMETRIC)

SIGMAV

VECTOR[SYMMETRIC] of regime-specific covariance matrices if the variance is switching.

 

Examples (of Procedure Itself)

The first sets up a a 4 lag autoregression with means (only) switching. This is the Hamilton(1989) model.

 

@msvarsetup(lags=4,switch=m)

# dusa



 

This is a six variable, 1 lag VAR with means (only) switching, as that's the default for the SWITCH option.

 

@msvarsetup(lags=1,regimes=2)

# dusa djap dfrg duk dcan daus



 

This is a six variable, 4 lag VAR with intercepts and covariance matrices switching. The lag coefficients are fixed between regimes.

 

@msvarsetup(lags=4,regimes=2,switch=ih)

# dusa djap dfrg duk dcan daus

 

Procedures and Functions

 

@MSVARInitial(guessregimes=SERIES[INTEGER]) start end

by default, computes a "standard" set of initial guess values for the parameters. The default guesses have intercepts or means increasing from small to large based upon a set of full-sample estimates of the model. All lag coefficients and covariance matrices are fixed across regimes. That would be appropriate if either you are only allowing the mean or intercept to switch, or if you believe that those are the main differences in regimes. As an alternative, you can use the GUESSREGIMES option to input a SERIES[INTEGER] (with values 1, 2, ..., number of regimes) with "guesses" for which entries are in which regimes, and the guess values will be generated based upon regressions over the subsamples.

 

If you leave off the start and/or end parameters, the maximum available range given the series and lags involved will be used.

 

@MSVARParmset(parmset=PARMSET to define)

defines a PARMSET with the free parameters for the switching VAR given the options (all except the transition probability parameters).


 

%MSVARMarginal(pexpand,lags)

returns a VECTOR of marginal probabilities for states or tuples of states given an expanded vector of probabilities (pexpand). lags is the number of lags in the tuple. lags=0 is used to get just the current state, 1 gives the pairs of state(t),state(t-1), etc.

 

%MSVARFVec(time)

returns the vector of likelihoods (not in log form) for the (expanded) states at time.

 

%MSVARProb(time)

compute the likelihood (not logged) of the model at time for the current set of parameters. As a side effect, it computes pt_t1(time) and pt_t(time)
 

 

%MSVARInit()

does the calculations needed at the start of each function evaluation


 

%MSVARInitTransition()

for a model with fixed transitions, expands the transition matrix if required and scans for negative probabilities. Returns 1 if the probabilities are all non-negative, and 0 if not.


 

@MSVARSmoothed gstart gend psmoothed

calculates the smoothed (marginal) probabilities of the states, that is psmoothed(t) is the smoothed probability of being at the various states at time t. (For models with switching means, the smoothing algorithm has to be applied to the expanded state vector).


 

@MSVARStdResiduals start end resids

computes a VECT[SERIES] of one-step standardized residuals for diagnostic purposes.


 

@MSVARResids(regimes=SERIES[INT] of regime,specific=single regime) start end

computes a VECT[SERIES] of regime-specific residuals for computational purposes. (Note, these have no direct diagnostic value—use @MSVARStdResids for that). You can either get the residuals for a set of time-varying regime values, using the REGIMES option, which takes values 1, 2, ... number of regimes, or can get all residuals for one specific setting for the regime across the entire sample by using the SPECIFIC option (which again takes a single value from 1, 2, ... number of regimes).
 

For EM algorithm

@MSVAREMGeneralSetup

needs to be called before using EM to set up the work arrays

@MSVAREMStep(options) gstart gend

@MSVAREStep  gstart gend

@MSVARMStep(options) gstart gend

@MSVAREMStep does the combined E and M steps, @MSVAREStep does only the E, and @MSVARMStep does only the M. @MSVAREMStep and @MSVARMStep both have options to restrict the set of parameters that are updated, so some can be fixed.
 

For MCMC

@MSVARRelabel  swaps

reorders all switching components based upon the index array swaps.


 


Copyright © 2025 Thomas A. Doan