Page 1 of 2
Filardo (1994) using Maximum Likelihood, Guess Values
Posted: Mon Aug 08, 2016 9:40 am
by Jules89
Dear Tom,
I have rewriten the replication code for the Filardo (1994) paper, because I wanted to estimate the model by maximum likelihood.
This is my Code:
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 ****************************
*****************************************************************************************
source msvarsetup.src
compute nlags=4
compute gstart=1948:6,gend=1992:8
@MSVARSetup(lags=nlags, Switch=M)
# g
nonlin(parmset=common) mu phi sigmav
**********************************************************************
******************** 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
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
I would like to use this code for other applications as a "cooking recipe".
My first question is: Is the code right or are there any mistakes? I checked the results and they are close to the Filardo Paper.
My second question is: Where do the guess values for v1 and v2 come from? I do not understand why the first elements of the two vectors are set equal to log(0.7/0.3) and log(0.95/0.05). Is there any general method for deriving the guess values or can these values be used for any markov switching VAR model?
Thank you in advance
Jules
Re: Filardo (1994) using Maximum Likelihood, Guess Values
Posted: Mon Aug 08, 2016 11:18 am
by TomDoan
Those are inverting the logistic. To get the logistic index to create a probability of p, you want z=log(p/(1-p)). So those are solving for different target values of p.
Re: Filardo (1994) using Maximum Likelihood, Guess Values
Posted: Tue Aug 09, 2016 2:33 am
by Jules89
Hello Tom,
thank you for the quick reply. I don't understand what you mean by "So those are solving for different target values of p".
Where do for example come the numbers 0.7 and 0.95 from? At first I thought, that those might be the value that create the probabilities for the fixed transition model (when inserted into the normal), but I get completely different probabilities when I am estimating the model with ftp. So are the numbers random or did I do something wrong?
Best
Jules
Re: Filardo (1994) using Maximum Likelihood, Guess Values
Posted: Tue Aug 09, 2016 2:18 pm
by TomDoan
For compatibility with the original paper, the second regime probability actually generates the p(2,2) value. (It's common in two-regime models to estimate the diagonals of the transition; however, that doesn't generalize to more than two regimes, so that's not how RATS does it in general). Note how the p(1,2) probability uses the 1/(1+z) rather than z/(1+z) which flips over the logistic calculation. Thus .95 for staying in the growth regime probably isn't a bad guess at a monthly level. The .7 is the (smaller) guess probability for staying in the recession regime.
Re: Filardo (1994) using Maximum Likelihood, Guess Values
Posted: Wed Aug 10, 2016 7:28 am
by Jules89
So does that mean, that for v2=log(.95/.05)~~0.0 calculates a guess value for p(2,2) and v1=log(.7/.3)~~0.0 calculates a guess value for p(1,1)?
Because I thought that v2=log(.95/.05)~~0.0 calculates a guess value for p(1,2).
Re: Filardo (1994) using Maximum Likelihood, Guess Values
Posted: Wed Aug 10, 2016 7:47 am
by TomDoan
I just explained that. As this is written (because of the way p(1,2) is computed) v2 is actually for p(2,2).
Re: Filardo (1994) using Maximum Likelihood, Guess Values
Posted: Wed Aug 10, 2016 9:50 am
by Jules89
Thank you very much, I was just confused because in the Filardo replication code when it comes to overwriting the transition matrix the following was written:
"compute p(1,2)=%(z=exp(%dot(%eqnxvector(p2eq,time),v2)),1/(1+z))" But then everything is clear on this point.
I have one more general question when it comes to MS-TVTP models. To maximize the likelihood I have to insert guess values for the logit model in the transition matrix. In the Filardo case it is somehow assumed that the probabilities for staying in state 1 and state 2 are 0.7 and 0.95, but where do those values actually come from. You wrote "Thus .95 for staying in the growth regime probably isn't a bad guess at a monthly level. The .7 is the (smaller) guess probability for staying in the recession regime." Did you just played around with different values and figuered those out to be the best or is there any way of finding good initial values? Because when I want to use the MS-VAR-TVTP framework for different applications I have got the problem of finding initial values... So is there any good way to initialize your parameters? The other parameters can be initialized by using @MSVARInitial right?
Best
Jules
Re: Filardo (1994) using Maximum Likelihood, Guess Values
Posted: Wed Aug 10, 2016 10:33 am
by TomDoan
If you understand how Markov chains work, if P(stay)=.95, then the expected length of a stay is 1/(1-.95)=20 and if it's .70, then it's 1/(1-.70)~3.3. Those may actually be a little small when measured in months, but you don't want guess values to start too close to 1's. The @MSVARInitial initializes everything else, but note that that's assuming that the principal difference is in the mean/intercept. Even if you allow the VAR coefficients to change, the guess values make those equal across regimes.
Re: Filardo (1994) using Maximum Likelihood, Guess Values
Posted: Wed Aug 10, 2016 11:27 am
by Jules89
Hey Tom,
thank you for the quick reply.
You said:
"The @MSVARInitial initializes everything else, but note that that's assuming that the principal difference is in the mean/intercept. Even if you allow the VAR coefficients to change, the guess values make those equal across regimes."
What do you mean by that?
Another question is whether @MSVARInital is also appropirate to use when I have a switching mean AND a switching variance. Or do I have to compute guess values on my own then?
Thank you in advance
Jules
Re: Filardo (1994) using Maximum Likelihood, Guess Values
Posted: Wed Aug 10, 2016 12:04 pm
by TomDoan
I would strongly urge you to get the
Structural Breaks and Switching Models e-course which has roughly 140 pages of coverage of mixture and MS models of various sorts.
The intention of most people who allow switching means and switching variances is that the regimes will be determined by the means and they just don't want to fix the variances. Unfortunately, that usually isn't what happens---the differing variances tend to dominate the likelihood. There are also some gnarly technical issues when variances switch, as the likelihood is unbounded.
Re: Filardo (1994) using Maximum Likelihood, Guess Values
Posted: Wed Aug 10, 2016 12:09 pm
by Jules89
I have the Rats Handbook for Switching Models and Structural Breaks from 2012... Is it the same? Because I could not find any information on intitial values
Re: Filardo (1994) using Maximum Likelihood, Guess Values
Posted: Wed Aug 10, 2016 1:38 pm
by TomDoan
There are descriptions in each of the sections about how the guess values are chosen. The Ehrmann-Ellison-Valla example, for instance, overrides the standard guesses because the hope is to separate regimes based upon the variance of the oil price. Particularly if you're going to a MS-VAR it's a very good idea to use EM since it takes care of the great mass of VAR lag coefficients constructively.
One thing to remember is that there is no guarantee that an MS model will fit or if it fits that it will produce results that make sense. I remember reading one (published) paper where there were five pages of diagnostics to show that the model was "correct" to cover for the fact that the results made no economic sense.
Re: Filardo (1994) using Maximum Likelihood, Guess Values
Posted: Thu Aug 11, 2016 8:41 am
by Jules89
Hello Tom,
again I have problems with replicating the Filardo (1994) paper... The code is like the one above, but when I want to estimate it with more than one triggervariable (for example with an additional lag) as in the original replication file, Rats sets the estimates and the statdarderrors and everything else to zero.
Here is one example:
Code: Select all
*********************************************************************
******************* Various other combinations **********************
*********************************************************************
@MSVARInitial gstart gend
equation p1eq *
# constant cligr{1 2}
equation p2eq *
# constant cligr{1 2}
compute v1=log(.7/.3)~~0.0~~0.0
compute v2=log(.95/.05)~~0.0~~0.0
compute mu(1)=-1.7,mu(2)=.3
maximize(parmset=tv+common,start=(pstar=TVPInit()),$
method=bfgs, iters=300) logltvtp gstart gend
Which produces:
Code: Select all
MAXIMIZE - Estimation by BFGS
Convergence in 12 Iterations. Final criterion was 0.0000020 <= 0.0000100
LOW ITERATION COUNT ON BFGS MAY LEAD TO POOR ESTIMATES FOR STANDARD ERRORS
Monthly Data From 1948:06 To 1992:08
Usable Observations 531
Function Value -602.9636
Variable Coeff Std Error T-Stat Signif
************************************************************************************
1. V1(1) 1.116782174 0.369673740 3.02099 0.00251946
2. V1(2) 0.000000000 0.000000000 0.00000 0.00000000
3. V1(3) 0.000000000 0.000000000 0.00000 0.00000000
4. V2(1) 3.535889116 0.375871950 9.40716 0.00000000
5. V2(2) 0.000000000 0.000000000 0.00000 0.00000000
6. V2(3) 0.000000000 0.000000000 0.00000 0.00000000
7. MU(1)(1) -1.396499000 0.210008343 -6.64973 0.00000000
8. MU(2)(1) 0.431383365 0.086882381 4.96514 0.00000069
9. PHI(1)(1,1) 0.296792257 0.050738464 5.84945 0.00000000
10. PHI(2)(1,1) 0.114351707 0.052184182 2.19131 0.02842939
11. PHI(3)(1,1) 0.134189197 0.053444544 2.51081 0.01204539
12. PHI(4)(1,1) 0.076690167 0.051078726 1.50141 0.13324926
13. SIGMA(1,1) 0.438300055 0.033377972 13.13142 0.00000000
So there must be something wrong with my way of adjusting the replication code.... Can you plese have a look at it and tell me whats wrong?
Thank you in advance
Jules
Re: Filardo (1994) using Maximum Likelihood, Guess Values
Posted: Thu Aug 11, 2016 9:47 am
by TomDoan
You didn't post an entire program, so I can't tell if you got something wrong in between. However, I tacked the piece you just posted onto the one you posted before and it seems to work fine:
Code: Select all
MAXIMIZE - Estimation by BFGS
Convergence in 19 Iterations. Final criterion was 0.0000024 <= 0.0000100
Monthly Data From 1948:06 To 1992:08
Usable Observations 531
Function Value -591.3204
Variable Coeff Std Error T-Stat Signif
************************************************************************************
1. V1(1) 0.255131176 0.608067990 0.41958 0.67479469
2. V1(2) -0.296251989 0.614655497 -0.48198 0.62981977
3. V1(3) -2.427630173 1.094216439 -2.21860 0.02651385
4. V2(1) 3.563140037 0.469928926 7.58230 0.00000000
5. V2(2) 0.877442683 0.366608579 2.39340 0.01669282
6. V2(3) -0.197577512 0.322369830 -0.61289 0.53994853
7. MU(1)(1) -1.134124276 0.185409677 -6.11686 0.00000000
8. MU(2)(1) 0.446168282 0.072174696 6.18178 0.00000000
9. PHI(1)(1,1) 0.245040054 0.050377690 4.86406 0.00000115
10. PHI(2)(1,1) 0.086322555 0.052465243 1.64533 0.09990210
11. PHI(3)(1,1) 0.134093645 0.054146868 2.47648 0.01326850
12. PHI(4)(1,1) 0.096659608 0.052855948 1.82874 0.06743907
13. SIGMA(1,1) 0.441450853 0.031524189 14.00356 0.00000000
Re: Filardo (1994) using Maximum Likelihood, Guess Values
Posted: Thu Aug 11, 2016 10:53 am
by Jules89
I guess it was because I added @MSVARInitial gstart gend every time I initialized a new TVTP model. After I delted it and started everything new it worked...
What I am doing now is working on the following code
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 ****************************
*****************************************************************************************************
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
nonlin(parmset=contp) p
@MSVARInitial gstart gend
frml logltvtp = log(%MSVarProb(t))
maximize(parmset=common+contp,start=(pstar=%MSVARInit()), reject=%MSVARInitTransition()==0.0,$
method=bfgs, pmethod=Simplex, piters=5) logltvtp gstart gend
***********************************************************************************
******************** Adjusting fo 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 *******************
**********************************************************************
*** Define the logistic index for the transitions
equation p1eq *
# constant cligr{1}
equation p2eq *
# constant cligr{1}
***Starting Values to make state 1 the low growth state
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
Before I always put an additional @MSVARINITIAL and another frml logltvtp = log(%MSVarProb(t)) before every MAXIMIZE instruction. I think that caused some trouble.