Adjusting your code to allow for three states is quite simple:
- Code: Select all
cal(m) 1990:1
open data eu27yptc.xls
data(format=xls,org=columns) 1990:1 2010:5
*
set g = 100*log(prodtc/prodtc{1})
graph(header="EU 27 industrial production growth")
# g
*
* Change this to states=3<<<<<<
*
@msvarsetup(lags=1,switch=m,states=3)
# g
compute gstart=1991:2,gend=2010:5
frml msvarf = log(%MSVARProb(t))
*
* Change this to use the logistic parameterization (theta rather than p) <<<<<
*
nonlin(parmset=msparms) theta
nonlin(parmset=varparms) mu phi sigma
@msvarinitial gstart gend
*
* Add the p=%mslogisticp(theta) to the start=%(..). (Also need the %(...,...)
* around the two calculations in start=.. <<<<<
*
maximize(parmset=varparms+msparms,$
start=%(p=%MSLOGISTICP(theta),pstar=%MSVARInit()),$
reject=%MSVARInitTransition()==0.0,$
pmethod=simplex,piters=5,method=bfgs) msvarf gstart gend
@msvarsmoothed gstart gend psmooth
set pcontract gstart gend = psmooth(t)(1)
set pcrash gstart gend = psmooth(t)(3)
*
* To create the shading marking the recessions, create a dummy series
* which is 1 when the recessq series is 1, and 0 otherwise. (recessq is
* 1 for NBER recessions and -1 for expansions).
*
*set contract = recessq==1
*
spgraph(vfields=2)
graph(header="Quarterly Growth Rate of EU27 Industrial production")
# g %regstart() %regend()
graph(style=polygon,header="Probability of Economy Being in Contraction")
# pcontract %regstart() %regend()
spgraph(done)
Unfortunately, the recession in 2008 is so severe that your three "states" are the crash, the entrance/exit to the crash and the everything else. It's quite possible that that's a local mode, and that you can find a more natural breakdown into crash, ordinary recession, expansion, but that might take a bit of fussing with guess values. (Maybe fix the mu's and estimate everything else first).