I have rewritten the Filardo (1994) paper replication for maximum likelihood.
The code is below:
Code: Select all
****************************************************************************************
************************* Reading in and Transforming the Data *************************
****************************************************************************************
cal(m) 1948
open data filardo.dat
data(format=prn,org=cols) 1948:1 1992:8 year month ip cli dfi xli sp fed tspread
set ipgr = 100.0*log(ip/ip{1})
stats(noprint) ipgr * 1959:12
compute stdearly=sqrt(%variance)
stats(noprint) ipgr 1960:1 *
compute stdlate=sqrt(%variance)
set ipgradjust = %if(t<=1959:12,ipgr*stdlate/stdearly,ipgr)
set g = ipgradjust
set cligr = 100.0*log(cli/cli{1})
set spgr = 100.0*log(sp/sp{1})
set xlidiff = xli-xli{1}
set ffdiff = fed-fed{1}
set tspdiff = tspread-tspread{1}
set dfismooth = dfi+2*dfi{1}+2*dfi{2}+dfi{3}
* Center variabes to zero means
dofor s = cligr spgr xlidiff ffdiff tspdiff dfismooth
diff(center) s
end dofor s
*****************************************************************************************************
**************************** Setting up the Markov Switching Constant TP ****************************
*****************************************************************************************************
*****************************************************************************************
**************************** Setting up the Markov Switching ****************************
*****************************************************************************************
source msvarsetup.src
compute nlags=4
compute gstart=1948:6,gend=1992:8
@MSVARSetup(lags=nlags, Switch=M)
# g
nonlin(parmset=common) mu phi sigma
**********************************************************************
******************** Time varying probabilities **********************
**********************************************************************
dec equation p1eq p2eq
dec vector v1 v2
nonlin(parmset=tv) v1 v2
**********************************************************************
********** Overwriting the standard fixed transition matrix **********
**********************************************************************
function %MSVARPmat time
type rect %MSVARPmat
type int time
*
local integer i j
local rect pexpand
local real z
*
compute p(1,1)=%(z=exp(%dot(%eqnxvector(p1eq,time),v1)),z/(1+z))
compute p(1,2)=%(z=exp(%dot(%eqnxvector(p2eq,time),v2)),1/(1+z))
compute %MSVARInitTransition()
*
if nexpand==nstates {
dim pexpand(nstates,nstates-1)
ewise pexpand(i,j)=%if(i==nstates,-1.0,i==j)
compute %MSVARPmat=pexpand*p
ewise %MSVARPmat(i,j)=%if(i==nstates,1.0+%MSVARPmat(i,j),%MSVARPmat(i,j))
}
else {
dim %MSVARPmat(nexpand,nexpand)
ewise %MSVARPmat(i,j)=MSVARTransProbs(MSVARTransLookup(i,j))
}
end
**********************************************************************
******* Initialize the probabilities using only the intercepts *******
**********************************************************************
function TVPInit
type vector TVPInit
*
local rect a
local integer i j
*
compute p=||%logistic(v1(1),1.0),1-%logistic(v2(1),1.0)||
compute TVPInit=%MSVARInit()
end
**********************************************************************
********************* Calculating the Likelihood *********************
**********************************************************************
frml logltvtp = %MSVARPMat(t),log(%MSVarProb(t))
**********************************************************************
****************** Initialize the other Parameters *******************
**********************************************************************
@MSVARInitial
*** Define the logistic index for the transitions
equation p1eq *
# constant cligr{1}
equation p2eq *
# constant cligr{1}
***Starting Values Except Sigma (initialized in @MSVARInitial)
compute v1=log(.7/.3)~~0.0
compute v2=log(.95/.05)~~0.0
compute mu(1)=-1.7,mu(2)=.3
*********************************************************************
**************** Maximization of the Log-Likelihood *****************
*********************************************************************
maximize(parmset=tv+common,start=(pstar=TVPInit()),$
method=bfgs) logltvtp gstart gend
Code: Select all
********************************************************************
****************** Plotting the Regime Probability ******************
*********************************************************************
@msvarsmoothed gstart gend psmooth
set prs1 gstart gend = PSMOOTH(t)(1)
set prs2 gstart gend = PSMOOTH(t)(2)
set pr1 gstart gend = pt_t(t)(1)
set pr2 gstart gend = pt_t(t)(2)
spgraph(vfields=2)
graph(style=line, header="Probability State 1 Unsmoothed")
# pr1
graph(style=line, header="Probability State 2 Unsmoothed")
# pr2
spgraph(done)
spgraph(vfields=2)
graph(style=line, header="Probability State 1 Smoothed")
# prs1
graph(style=line, header="Probability State 2 Smoothed")
# prs2
spgraph(done)
Thank you very much in advance
Jules