*
* HAMILTON.PRG
* Hamilton Markov chain model for US GNP from page 697 of Hamilton,
* "Time Series Analysis"
*
cal(m) 1990:1
open data eu27yptc.xls
data(format=xls,org=columns) 1990:1 2010:5
*
set g = 100*log(prodtc/prodtc{12})
graph(header="EU 27 industrial production growth")
# g
*
@msvarsetup(lags=1,switch=m)
# g
compute gstart=1991:2,gend=2010:5
frml msvarf = log(%MSVARProb(t))
*
nonlin(parmset=msparms) p
nonlin(parmset=varparms) mu phi sigma
@msvarinitial gstart gend
maximize(parmset=varparms+msparms,$
  start=(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)(2)
*
* 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)


