0% found this document useful (0 votes)
480 views51 pages

Intro To MSM With STATA

1 When we use Markov-Switching Regression Models 2 Introductory concepts 3 Markov-Switching Dynamic Regression Predictions State probabilities predictions Level predictions State expected durations Transition probabilities 4 Markov-Switching AR Models
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
480 views51 pages

Intro To MSM With STATA

1 When we use Markov-Switching Regression Models 2 Introductory concepts 3 Markov-Switching Dynamic Regression Predictions State probabilities predictions Level predictions State expected durations Transition probabilities 4 Markov-Switching AR Models
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

Introduction to Markov-switching regression models

using the mswitch command

Gustavo Sánchez

StataCorp

October 22, 2015


Madrid, Spain

(StataCorp) Markov-switching regression in Stata October 22 1/1


Introduction to Markov-switching regression models
using the mswitch command

Gustavo Sánchez

StataCorp

October 22, 2015


Madrid, Spain

(StataCorp) Markov-switching regression in Stata October 22 2/1


Outline

1 When we use Markov-Switching Regression Models


2 Introductory concepts
3 Markov-Switching Dynamic Regression
Predictions
State probabilities predictions
Level predictions
State expected durations
Transition probabilities

4 Markov-Switching AR Models

(StataCorp) Markov-switching regression in Stata October 22 3/1


When we use Markov-Switching Regression Models

The parameters of the data generating process (DGP) vary over a


set of different unobserved states.

We do not know the current state of the DGP, but we can estimate
the probability of each possible state.

(StataCorp) Markov-switching regression in Stata October 22 4/1


When we use Markov-Switching Regression Models

Some examples:
In economics
Asymmetrical behavior over GDP expansions and recessions
(Hamilton 1989).
Exchange rates (Engel and Hamilton 1990).
Interest rates (García and Perron 1996).
Stock returns (Kim et al. 1998).

In epidemiology: Incidence rates of infectious disease in epidemic


and nonepidemic states (Lu et al. 2010).
In psychology: manic depressive states (Hamaker et al. 2010).

(StataCorp) Markov-switching regression in Stata October 22 5/1


When we use Markov-Switching Regression Models

The time series in all those examples are characterized by DGPs


with dynamics that are state dependent.

States may be recessions and expansions, high/low volatility,


depressive/non-depressive, epidemic/non-epidemic states, etc.

Any of the parameters (beta estimates, sigma, AR components)


may be different for each state.

(StataCorp) Markov-switching regression in Stata October 22 6/1


Different volatilities - IPC for Spain

(StataCorp) Markov-switching regression in Stata October 22 7/1


Different volatilities - IPC for Spain

(StataCorp) Markov-switching regression in Stata October 22 8/1


Different State Levels? - Fertility rate Spain 1960-2014

(StataCorp) Markov-switching regression in Stata October 22 9/1


Different State Levels? - Fertility rate Spain 1960-2014

(StataCorp) Markov-switching regression in Stata October 22 10 / 1


Different AR structure Levels? - Interbank interest rate UEM

(StataCorp) Markov-switching regression in Stata October 22 11 / 1


Introductory Concepts

(StataCorp) Markov-switching regression in Stata October 22 12 / 1


Markov-Switching Regression Models

Models for time series that transition over a set of finite states.

States are unobserved and the process can switch among states
throughout the sample.

The time of transition between states and the duration in a


particular state are both random.

The transitions follow a Markov process.

We can estimate state-dependent and state-independent


parameters.

(StataCorp) Markov-switching regression in Stata October 22 13 / 1


Markov-Switching Regression Models

Let’s then define a Markov Chain:

Assume the states are defined by a random variable St that takes


the integer values 1, 2, ..., N.

Then, the probability of the current state, j, only depends on the


previous state:

P(St = j|St−1 = i, St−2 = k , St−3 = w...) = P(St = j|St−1 = i) = pij

(StataCorp) Markov-switching regression in Stata October 22 14 / 1


Markov-Switching Regression Models

Let’s define a simple constant only model with three states:

yt = µs + εt
Where:
µs = µ1 if s=1
µs = µ2 if s=2
µs = µ3 if s=3

We do not know with certainty the current state, but we can


estimate the probability.
We can also estimate the transition probabilities:
pij : probability of being in state j in the current period given that the
process was in state i in the previous period.

(StataCorp) Markov-switching regression in Stata October 22 15 / 1


Transition probabilities, expected duration, tests

We will then be interested in obtaining the matrix with the


transition probabilities:
 
p11 p12 p13
 p21 p22 p23 
p31 p32 p33
Where:
p11 + p12 + p13 = 1
p21 + p22 + p23 = 1
p31 + p32 + p33 = 1

We will also be interested in the expected duration for each state.


We can perform tests for comparing parameters across states

(StataCorp) Markov-switching regression in Stata October 22 16 / 1


Markov-switching dynamic regression

(StataCorp) Markov-switching regression in Stata October 22 17 / 1


Markov-switching dynamic regression

Allow states to switch according to a Markov process

Allow for quick adjustments after a change of state.

Often applied to high frequency data (monthly,weekly,etc.)

(StataCorp) Markov-switching regression in Stata October 22 18 / 1


Markov-switching dynamic regression

The model can be written as:

yt = µs + xt α + zt βs + s,t

Where:
yt : Dependent variable

µs : State-dependent intercept
xt : Vector of exog. variables with state invariant coefficients α
zt : Vector of exog. variables with state-dependent coefficients βs
s,t ~iid N(0, σs2 )

(StataCorp) Markov-switching regression in Stata October 22 19 / 1


Markov-switching dynamic regression

mswitch dr depvar [nonswitch_varlist] [if] [in] [, options]

(StataCorp) Markov-switching regression in Stata October 22 20 / 1


Markov switching dynamic regression

Example 1:
Consumer price index for Spain 2011=100
Period: 1961m1 - 2015m8
Source: Banco de España

(StataCorp) Markov-switching regression in Stata October 22 21 / 1


Markov switching dynamic regression with three states

Code (D. indicates first difference)

Fit the model


mswitch dr D.ipc, states(3) varswitch nolog

Predict probabilities of being at each state


predict pr_state1 pr_state2 pr_state3, pr

(StataCorp) Markov-switching regression in Stata October 22 22 / 1


Markov switching dynamic regression with three states

. mswitch dr D.ipc,states(3) varswitch nolog


Markov-switching dynamic regression
Sample: 1961m2 - 2015m8 No. of obs = 655
Number of states = 3 AIC = -0.8669
Unconditional probabilities: transition HQIC = -0.8350
SBIC = -0.7847
Log likelihood = 295.91091

D.ipc Coef. Std. Err. z P>|z| [95% Conf. Interval]

State1
_cons .2060383 .0089781 22.95 0.000 .1884416 .223635

State2
_cons .0262835 .0027906 9.42 0.000 .020814 .0317529

State3
_cons .1668645 .0430856 3.87 0.000 .0824182 .2513108

sigma1 .1594772 .0065446 .1471524 .1728342

sigma2 .0321699 .0020182 .0284478 .0363791

sigma3 .5534114 .0306889 .4964158 .6169509

(StataCorp) Markov-switching regression in Stata October 22 23 / 1


MSDR - Example 1: Probability of being in State 1

(StataCorp) Markov-switching regression in Stata October 22 24 / 1


Markov switching dynamic regression with three states

. mswitch dr D.ipc,states(3) varswitch nolog


Markov-switching dynamic regression
Sample: 1961m2 - 2015m8 No. of obs = 655
Number of states = 3 AIC = -0.8669
Unconditional probabilities: transition HQIC = -0.8350
SBIC = -0.7847
Log likelihood = 295.91091

D.ipc Coef. Std. Err. z P>|z| [95% Conf. Interval]

State1
_cons .2060383 .0089781 22.95 0.000 .1884416 .223635

State2
_cons .0262835 .0027906 9.42 0.000 .020814 .0317529

State3
_cons .1668645 .0430856 3.87 0.000 .0824182 .2513108

sigma1 .1594772 .0065446 .1471524 .1728342

sigma2 .0321699 .0020182 .0284478 .0363791

sigma3 .5534114 .0306889 .4964158 .6169509

(StataCorp) Markov-switching regression in Stata October 22 25 / 1


MSDR - Example 1: Probability of being in State 2

(StataCorp) Markov-switching regression in Stata October 22 26 / 1


Markov switching dynamic regression with three states

. mswitch dr D.ipc,states(3) varswitch nolog


Markov-switching dynamic regression
Sample: 1961m2 - 2015m8 No. of obs = 655
Number of states = 3 AIC = -0.8669
Unconditional probabilities: transition HQIC = -0.8350
SBIC = -0.7847
Log likelihood = 295.91091

D.ipc Coef. Std. Err. z P>|z| [95% Conf. Interval]

State1
_cons .2060383 .0089781 22.95 0.000 .1884416 .223635

State2
_cons .0262835 .0027906 9.42 0.000 .020814 .0317529

State3
_cons .1668645 .0430856 3.87 0.000 .0824182 .2513108

sigma1 .1594772 .0065446 .1471524 .1728342

sigma2 .0321699 .0020182 .0284478 .0363791

sigma3 .5534114 .0306889 .4964158 .6169509

(StataCorp) Markov-switching regression in Stata October 22 27 / 1


MSDR - Example 1: Probability of being in State 3

(StataCorp) Markov-switching regression in Stata October 22 28 / 1


Markov switching dynamic regression

Example 2:
Fertility rate (total births per woman) for Spain
Period: 1960 - 2013
Source: World Bank

(StataCorp) Markov-switching regression in Stata October 22 29 / 1


Markov switching dynamic regression

Example 2: Fertility rate in Spain (1960-2013)

Variables:

fertility: Fertility rate (total births per woman) for Spain

ch_mortality: Mortality rate, under 5 (per 1,000 live births)

gni_pcapita: GNI per capita (thousands - 2005 US$)

school_access: Primary and secondary school enrollment,


(gross), gender parity index_(GPI)

(StataCorp) Markov-switching regression in Stata October 22 30 / 1


Markov switching dynamic regression

Fit the model


mswitch dr D.fertility D.ch_mortality, states(2) varswitch ///
switch(D.gni_pcapita D.school_access) vsquish

Test on equality of coefficients across states


test _b[State1:D.school_access]=_b[State2:D.school_access],notest
test _b[State1:D.gni_pcapita]=_b[State2:D.gni_pcapita],accumulate

Transition probabilities and expected duration


estat transition
estat duration

(StataCorp) Markov-switching regression in Stata October 22 31 / 1


Markov switching dynamic regression for fertility rate

. mswitch dr D.fertility D.ch_mortality, states(2) varswitch ///


> switch(D.gni_pcapita D.school_access) vsquish
Markov-switching dynamic regression

D.fertility Coef. Std. Err. z P>|z| [95% Conf. Interval]

D.fertility
ch_mortality
D1. .0632344 .0107531 5.88 0.000 .0421587 .08431

State1
gni_pcapita
D1. .0434944 .0115159 3.78 0.000 .0209236 .0660652
school_access
D1. -1.042254 .1833868 -5.68 0.000 -1.401686 -.6828228
_cons -.058854 .0117087 -5.03 0.000 -.0818027 -.0359054

State2
gni_pcapita
D1. .0647241 .0149331 4.33 0.000 .0354557 .0939925
school_access
D1. -1.15316 .557033 -2.07 0.038 -2.244925 -.0613957
_cons -.0078558 .0089525 -0.88 0.380 -.0254023 .0096907

sigma1 .0087495 .0020577 .0055183 .0138728

sigma2 .0372011 .0046423 .0291296 .0475091

(StataCorp) Markov-switching regression in Stata October 22 32 / 1


Markov switching dynamic regression for fertility rate

Test on the equality of coefficients across states


. test _b[State1:D.gni_pcapita]=_b[State2:D.gni_pcapita],notest
( 1) [State1]D.gni_pcapita - [State2]D.gni_pcapita = 0

. test _b[State1:D.school_access]=_b[State2:D.school_access],accumulate
( 1) [State1]D.gni_pcapita - [State2]D.gni_pcapita = 0
( 2) [State1]D.school_access - [State2]D.school_access = 0
chi2( 2) = 1.23
Prob > chi2 = 0.5411

Test on the equality of sigma across states


. test _b[lnsigma1:_cons]=_b[lnsigma2:_cons]
( 1) [lnsigma1]_cons - [lnsigma2]_cons = 0
chi2( 1) = 29.23
Prob > chi2 = 0.0000

(StataCorp) Markov-switching regression in Stata October 22 33 / 1


Markov switching dynamic regression for fertility rate

. mswitch dr D.fertility D.(ch_mortality gni_pcapita school_access), ///


> states(2) varswitch vsquish
Markov-switching dynamic regression

D.fertility Coef. Std. Err. z P>|z| [95% Conf. Interval]

D.fertility
ch_mortality
D1. .048953 .0072042 6.80 0.000 .034833 .0630729
gni_pcapita
D1. .0505516 .0091887 5.50 0.000 .0325422 .068561
school_access
D1. -.6381832 .2571355 -2.48 0.013 -1.142159 -.134207

State1
_cons -.0704097 .0082148 -8.57 0.000 -.0865104 -.054309

State2
_cons .0013952 .0071861 0.19 0.846 -.0126893 .0154798

sigma1 .019568 .0037427 .0134505 .0284678

sigma2 .0278482 .0041421 .0208062 .0372737

(StataCorp) Markov-switching regression in Stata October 22 34 / 1


Markov switching dynamic regression for fertility rate

Transition probabilities
. estat transition
Number of obs = 42

Transition Probabilities Estimate Std. Err. [95% Conf. Interval]

p11 .9178466 .06678 .6632132 .9844686

p12 .0821534 .06678 .0155314 .3367868

p21 .0311448 .0327426 .003818 .2123665

p22 .9688552 .0327426 .7876335 .996182

(StataCorp) Markov-switching regression in Stata October 22 35 / 1


Markov switching dynamic regression for fertility rate

Expected duration
. estat duration
Number of obs = 42

Expected Duration Estimate Std. Err. [95% Conf. Interval]

State1 12.17235 9.894526 2.969237 64.38565

State2 32.10806 33.75521 4.70884 261.9202

(StataCorp) Markov-switching regression in Stata October 22 36 / 1


Markov switching dynamic regression for fertility rate

(StataCorp) Markov-switching regression in Stata October 22 37 / 1


Markov-switching AR model

(StataCorp) Markov-switching regression in Stata October 22 38 / 1


Markov-switching AR model

Allow states to switch according to a Markov process

Allow a gradual adjustment after a change of state.

Often applied to lower frequency data (quarterly, yearly, etc.)

(StataCorp) Markov-switching regression in Stata October 22 39 / 1


Markov-switching AR model

The model can be written as:


P
X
yt = µst + xt α + zt βst + φi,st (yt−i − µst−i − xt−i α + zt−i βst−i ) + t,s
i=1

Where:
yt : Dependent variable
µst : State-dependent intercept

xt : Vector of exog. variables with state invariant coefficients α


zt : Vector of exog. variables with state-dependent coefficients βst
φi,st : i th AR term in state st
s,t ~iid N(0, σs2 )

(StataCorp) Markov-switching regression in Stata October 22 40 / 1


Markov switching AR model

Example 3:
Interbank interest rate for Spain
Period: 1989Q4 - 2015Q3
Source: Banco de España

(StataCorp) Markov-switching regression in Stata October 22 41 / 1


Markov switching AR model

Example 3: Interest rate in Spain (1990Q1-2015Q3)

Variables:

r_interbank: Three months interbank rate

ipc: Consumer price index

(StataCorp) Markov-switching regression in Stata October 22 42 / 1


Markov switching AR model

Fit the model

mswitch ar D.r_interbank D.ipc if tin(1990q2,2012q4), ///


states(2) ar(1) arswitch varswitch constant ///
switch(,noconstant) nolog

Transition probabilities and expected duration

estat transition
estat duration

(StataCorp) Markov-switching regression in Stata October 22 43 / 1


Markov switching AR model

. mswitch ar D.r_interbank D.ipc if tin(1990q2,2012q4),states(2) ar(1) ///


> arswitch nolog switch(,noconstant) constant varswitch vsquish
Markov-switching autoregression
Sample: 1990q2 - 2012q4 No. of obs = 91
Number of states = 2 AIC = 1.1681
Unconditional probabilities: transition HQIC = 1.2572

D.
r_interbank Coef. Std. Err. z P>|z| [95% Conf. Interval]

D.r_interb~k
ipc
D1. .1345492 .0430415 3.13 0.002 .0501895 .218909
_cons -.1287786 .0299325 -4.30 0.000 -.1874453 -.0701119

State1
ar
L1. -.5821326 .0868487 -6.70 0.000 -.7523529 -.4119122

State2
ar
L1. .600846 .1133802 5.30 0.000 .3786249 .8230671

sigma1 .10039 .021533 .0659346 .1528509

sigma2 .4279839 .0404373 .3556339 .5150526

(StataCorp) Markov-switching regression in Stata October 22 44 / 1


Markov switching AR model

. estat transition
Number of obs = 91

Transition Probabilities Estimate Std. Err. [95% Conf. Interval]

p11 .6238106 .1906249 .2523082 .8906938

p12 .3761894 .1906249 .1093062 .7476918

p21 .0917497 .0529781 .0282364 .2599153

p22 .9082503 .0529781 .7400847 .9717636

. estat duration
Number of obs = 91

Expected Duration Estimate Std. Err. [95% Conf. Interval]

State1 2.658235 1.346997 1.33745 9.148609

State2 10.89922 6.293423 3.847408 35.41533

(StataCorp) Markov-switching regression in Stata October 22 45 / 1


MSAR - Example 3: Probability of being in each State

(StataCorp) Markov-switching regression in Stata October 22 46 / 1


Markov switching AR model

. predict state*,yhat dynamic(tq(2012q4))


. forvalues i=1/2 {
2. generate y_st`i´=state`i´+L.r_interbank
3. }

(StataCorp) Markov-switching regression in Stata October 22 47 / 1


Markov switching AR model

Comparing results from a different dynamic model (ARCH)

. arch D.r_interbank D.ipc if tin(1990q2,2012q4),arch(1) ///


> garch(1) ar(1) nolog vsquish
ARCH family regression -- AR disturbances
Sample: 1990q2 - 2012q4 Number of obs = 91
Distribution: Gaussian Wald chi2(2) = 18.56
Log likelihood = -45.09683 Prob > chi2 = 0.0001

D. OPG
r_interbank Coef. Std. Err. z P>|z| [95% Conf. Interval]

r_interbank
ipc
D1. .0765736 .0491625 1.56 0.119 -.0197832 .1729305
_cons -.1778991 .081251 -2.19 0.029 -.3371482 -.0186501

ARMA
ar
L1. .5016758 .126954 3.95 0.000 .2528505 .7505011

ARCH
arch
L1. .3809789 .2505937 1.52 0.128 -.1101757 .8721334
garch
L1. .5630487 .2146123 2.62 0.009 .1424163 .983681
_cons .0227445 .0202104 1.13 0.260 -.0168671 .0623561

(StataCorp) Markov-switching regression in Stata October 22 48 / 1


Markov switching AR model

Comparing results from a different dynamic model (ARCH)

(StataCorp) Markov-switching regression in Stata October 22 49 / 1


Summary

1 When we use Markov-Switching Regression Models


2 Introductory concepts
3 Markov-Switching Dynamic Regression
Predictions
State probabilities predictions
Level predictions
State expected durations
Transition probabilities

4 Markov-Switching AR Models

(StataCorp) Markov-switching regression in Stata October 22 50 / 1


References

Engel, C., and J. D. Hamilton. 1990. Long swings in the dollar: Are they in the
data and do markets know it?. American Economic Review 80: 689—713.
Hamilton, J. D. 1989. A new approach to the economic analysis of nonstationary
time series and the business cycle. Econometrica 57: 357—384.
Garcia, R., and P. Perron. 1996. An analysis of the real interest rate under
regime shifts. Review of Economics and Statistics 78: 111—125.
Kim, C.-J., C. R. Nelson, and R. Startz. 1998. Testing for mean reversion in
heteroskedastic data based on Gibbs-sampling-augmented randomization.
Journal of Empirical Finance 5: 115—43.
Lu, H.-M., D. Zeng, and H. Chen. 2010. Prospective infectious disease outbreak
detection using Markov switching models. IEEE Transactions on Knowledge and
Data Engineering 22: 565—577.
Hamaker, E. L., R. P. P. P. Grasman, and J. H. Kamphuis. 2010.
Regime-switching models to study psychological processes. In Individual
Pathways of Change: Statistical Models for Analyzing Learning and
Development, ed. P. C. Molenaar and K. M. Newell, 155—168. Washington, DC:
American Psychological Association

(StataCorp) Markov-switching regression in Stata October 22 51 / 1

You might also like