Page 1 of 1

Hamilton Switching Model (new coding)

Posted: Thu Feb 25, 2010 5:01 pm
by TomDoan
This is the example of the Hamilton switching model from the RATS User's Guide, rewritten to use the MSVAR procedures. It requires the newest version of the MSVARSETUP file (http://www.estima.com/forum/viewtopic.php?f=7&t=512).

Code: Select all

*
* HAMILTON.PRG
* Hamilton Markov chain model for US GNP from page 697 of Hamilton,
* "Time Series Analysis"
*
cal(q) 1951:1
open data gnpdata.prn
data(format=prn,org=columns) 1951:1 1984:4
*
set g = 100*log(gnp/gnp{1})
graph(header="GNP growth")
# g
*
@msvarsetup(lags=4,switch=m)
# g
compute gstart=1952:2,gend=1984:4
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 US GNP",shade=contract)
# g %regstart() %regend()
graph(style=polygon,header="Probability of Economy Being in Contraction",shade=contract)
# pcontract %regstart() %regend()
spgraph(done)

Re: Hamilton Switching Model (new coding)

Posted: Tue Aug 09, 2011 7:11 am
by sana
Hi Tom
I tried to run the program but I faced a problem.
The output indicates an error:

## SX16. Missing Operand or Adjacent Operators
>>>>pstar=MSVARInitial(<<<<

Please can you suggest me a solution?
Your help will be much appreciated
Thanks

Re: Hamilton Switching Model (new coding)

Posted: Tue Aug 09, 2011 8:01 am
by TomDoan
sana wrote:Hi Tom
I tried to run the program but I faced a problem.
The output indicates an error:

## SX16. Missing Operand or Adjacent Operators
>>>>pstar=MSVARInitial(<<<<

Please can you suggest me a solution?
Your help will be much appreciated
Thanks
Copy and paste out of the code segment above instead of trying to re-type everything. That line is supposed to read %MSVARInit() not MSVARInitial()

Re: Hamilton Switching Model (new coding)

Posted: Wed Aug 10, 2011 7:53 am
by sana
Thank you for your prompt response. I tried again and here is the message:

## SX11. Identifier %MSVARPROB is Not Recognizable. Incorrect Option Field or Parameter Order?
>>>>f = log(%MSVARProb(<<<<

Re: Hamilton Switching Model (new coding)

Posted: Wed Aug 10, 2011 11:04 am
by TomDoan
If you read the original message, you need an updated MSVARSETUP.SRC file. You're using an older one. If you did download that, then it's not in the correct location to be read in automatically, so you would need do

source full path to new version of.../msvarsetup.src

before the @msvarsetup line. If you're still having problems, you should contact support@estima.com directly. Be sure you include your serial number and the version that you're using.