Page 1 of 1

Segment data to two different state

Posted: Wed Mar 13, 2013 3:11 pm
by Yangyang
Hi eveyone
Can anyone tell me how to divide my GDP data to different sentiment of the business, let's say expansion and recession.
Thanks a lot!

Shadow area of NBER

Posted: Wed Mar 13, 2013 4:50 pm
by Yangyang
Hi everyone
can anyone teach me how to draw the NBER as a shadow area and compare with the filter probability?
Thank you so much!

Re: Segment data to two different state

Posted: Wed Mar 13, 2013 6:35 pm
by TomDoan
There are quite a few examples of using the SHADING option to shade recession periods in graphs. The simplest is probably swchap14a.rpf in the Stock and Watson textbook examples. The hamilton.rpf example uses a series on the data set (rather than the one generated by @NBERCycles) and uses that for the shading in a graph with the switching model probabilities.

Re: Segment data to two different state

Posted: Thu Mar 14, 2013 10:04 am
by Yangyang
Thank you so much for your suggestions.
I have also one problem aboutthe two statements, how can i divide my data set to two states
accoding to Hamilton.
The mean the US GDP from the Markov switching model are both positive in two states, And i want to
divide it to two states and then compare with the NBER.
I tried stock price and unemployment rate, they are positive in the state 1 and negative in the state 2.
What is the problem for the difference between GDP and stock price, How can i interpret it?
Thank you so much! :D

Re: Segment data to two different state

Posted: Thu Mar 14, 2013 3:07 pm
by TomDoan
Yangyang wrote:Thank you so much for your suggestions.
I have also one problem aboutthe two statements, how can i divide my data set to two states
accoding to Hamilton.
The mean the US GDP from the Markov switching model are both positive in two states, And i want to
divide it to two states and then compare with the NBER.
In the original Hamilton paper, GDP growth is -.36 in the contractions and 1.16 in the expansions, so I'm not sure why you're saying that they are both positive.
Yangyang wrote: I tried stock price and unemployment rate, they are positive in the state 1 and negative in the state 2.
What is the problem for the difference between GDP and stock price, How can i interpret it?
Thank you so much! :D
Stock price changes have very little persistence, so a Markov switching model is unlikely to show anything useful. Unemployment rate changes will usually have some similarities (other than being opposite sign) to GDP growth, but they are considered to be a "lagging indicator" so you will still see stable unemployment even after a recession has started, and rising (or at least not falling) unemployment after the recession has ended.

It's important to note, however, that a Markov switching model doesn't divide the data points into two regimes like the NBER dummy does. Instead, it provides a probability of each data point being in one regime or the other. There are a fair number of data points on one side or the other of a recession where the regime is unclear, and that is represented by a probability somewhere in the middle (say between .25 and .75).

Re: Segment data to two different state

Posted: Fri Mar 15, 2013 6:58 am
by Yangyang
Thank you for your explanation!

I used two state MS model to estimate the US GDP from 1950:01 to 2012:04
the output i got is
St = 1: optimistic state, μ1 = 0.0135
St = 2: pessimistic state, μ2 = 0.0188
P11 = 0.963; P22 = 0.964
St = 1: ξ1 = 0.00002
St = 2: ξ2 = 0.00020
I do not know why i got this results, it is obvious paradoxical to commen sense,
which positive in the expansion and negative in the recession.
the majority periods of the log return of GDP are positive.

Re: Segment data to two different state

Posted: Fri Mar 15, 2013 10:26 am
by TomDoan
what are the xi's?

Re: Segment data to two different state

Posted: Fri Mar 15, 2013 6:13 pm
by Yangyang

Code: Select all

OPEN DATA "C:\Users\Yang\Desktop\Data of the thesis\GDP_1950_2012.XLS"
CALENDAR(Q) 1950:1
DATA(FORMAT=XLS,ORG=COLUMNS) 1950:01 2012:04 GDP
*******************************************************
set LGDP = log(GDP)
set DLGDP = LGDP - LGDP{1}
*******************************************************
**Markov switching for unemployment rate
@MSRegression(switch=ch, states=2) DLGDP
# constant
*
nonlin(parmset=regparms) betas sigsqv
nonlin(parmset=msparms)  p
*
gset pt_t    = %zeros(nstates,1)
gset pt_t1   = %zeros(nstates,1)
gset psmooth = %zeros(nstates,1)
*
compute gstart=1950:01,gend=2012:04
@MSRegInitial gstart gend
*
* Compute a lower bound on the permitted values of the variance to
* prevent convergence to a zero-variance spike.
*
compute sigmalimit=1.e-6*%minvalue(sigsqv)
*
frml logl = f=%MSRegFVec(t),pt_t1=%mcstate(p,pstar),$
  pt_t=pstar=%msupdate(f,pt_t1,fpt),log(fpt)
maximize(start=(pstar=%mcergodic(p)),parmset=regparms+msparms,$
  reject=%minvalue(sigsqv)<sigmalimit,$
  method=bfgs,pmethod=simplex,piters=5) logl gstart gend
*
@%mssmooth p pt_t pt_t1 psmooth
*
* Smoothed probabilities of the regimes
*
set p1smooth = psmooth(t)(1)
graph(footer="Smoothed Probabilities of Regime 1",max=1.0,min=0.0)
# p1smooth
GRAPH(STYLE=LINE,OVERLAY=LINE,HEADER="GDP VS probability of bull state",KEY=UPLEFT,SCALE=BOTH,EXTEND) 2
# DLGDP
# P1SMOOTH
*
do i=1,2
   disp "Conditional Mean for Regime" i $
     betas(i)(1)/(1-betas(i)(2)-betas(i)(3))
end do i
**********************************************************************************************************

Code: Select all

MAXIMIZE - Estimation by BFGS
Convergence in     8 Iterations. Final criterion was  0.0000018 <=  0.0000100
Quarterly Data From 1950:01 To 2012:04
Usable Observations                       251
Skipped/Missing (from 252)                  1
Function Value                       824.6962

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
1.  BETAS(1)(1)                  0.0134542133 0.0005377869     25.01774  0.00000000
2.  BETAS(2)(1)                  0.0188055081 0.0014353330     13.10184  0.00000000
3.  SIGSQV(1)                    0.0000249042 0.0000034692      7.17865  0.00000000
4.  SIGSQV(2)                    0.0001934011 0.0000304593      6.34949  0.00000000
5.  P(1,1)                       0.9626686590 0.0248750079     38.70024  0.00000000
6.  P(1,2)                       0.0360811756 0.0293281822      1.23026  0.21860121
**************************************************************************************
Those are the code and the output i was using, can you give some hints?
What do you mean xi's?

Thanks a lot!
Yang

Re: Segment data to two different state

Posted: Sat Mar 16, 2013 7:33 am
by TomDoan
First of all, the regimes in a switching model aren't globally identified---the likelihood is exactly the same if you change the interpretations. Ordinarily, you can force regime 1 to be "high" and regime 2 to be "low" (or vice versa) through your choices of guess values, but there is no guarantee that those will be maintained through the estimation process. So if they come out switched, just switch them back.

The main reason you are getting results that you don't like is that you are switching both the mean and the variance. You want the mean to determine the regime, but the likelihood maximizer is with the mean basically being constant and the variance shifting. You might be able to find a mode with low and high means by a more careful choice of guess values, but it probably will be a local mode.

BTW, the example that you're using (which is from Tsay's textbook for unemployment rates) had exactly the same problem---the regimes were more high-low variance than high-low means.

Re: Segment data to two different state

Posted: Sun Mar 17, 2013 2:19 am
by Yangyang
Thank you for the explaining!
Yes, should i say the structure breaks is from the volatility shift, because there is the narrow gap between mean
in two states.
If that is the case, which model should i choose?
Thank you!

Re: Segment data to two different state

Posted: Mon Mar 18, 2013 12:45 pm
by TomDoan
Yangyang wrote:Thank you for the explaining!
Yes, should i say the structure breaks is from the volatility shift, because there is the narrow gap between mean
in two states.
If that is the case, which model should i choose?
Thank you!
I assume that the volatility shift is not what you want. If you look at the results, it appears that there really isn't a "Markov" switching volatility shift, but simply a volatility break partway through the data set (both regimes are highly persistent). That's important enough for explaining the data that the desired Markovian switching of the mean isn't picked up. With a somewhat more complicated model, you could allow for a variance break at a known location, and then just switch the mean; or (with a still more complicated model) you would allow for separate variance and mean switching models.

Re: Segment data to two different state

Posted: Tue Mar 19, 2013 5:16 am
by Yangyang
Thanks, i am writing my master thesis now, i guess i am not competent to use
the complicated model for seperating the variance and mean switching.

Re: Segment data to two different state

Posted: Tue Mar 19, 2013 9:38 am
by TomDoan
Yangyang wrote:Thanks, i am writing my master thesis now, i guess i am not competent to use
the complicated model for seperating the variance and mean switching.
Examining how MS models can be rather sensitive to choice of a sample range might be a reasonable topic for a master's thesis. And that wouldn't require going beyond the basic MS models.