Balke(2000) Threshold VAR

Use this forum for posting example programs or short bits of sample code.
Darth Nisis
Posts: 6
Joined: Wed Oct 07, 2015 7:39 am

Re: Balke(2000) Threshold VAR

Unread post by Darth Nisis »

Thanks Tom

Another question. I modified the code in order to obtain a multiple regimes model (4 regimes, generated through a complex combination of 3 different threshold equations). The estimation of the model works well, but I'm having trouble with the impulse response functions. Depending how I write this section, the program either crashes (if a use * as a condition separator in the %if function), or the IRF's are equal across regimes (if I use +).

Code: Select all

do i=1,nvar
   frml tvarf(i) depvars(i) = %if((thrfrml1{d}>=thresh1)*(thrfrml2{d}<thresh2)*(thrfrml3{d}>=thresh3),$
        fitud(&i,1)+%dot(%xrow(smup,&i),bootres),$
        %if((thrfrml1{d}>=thresh1)*(thrfrml2{d}<thresh2)*(thrfrml3{d}<thresh3),$
        fitud(&i,2)+%dot(%xrow(smdn,&i),bootres),$
        %if((thrfrml1{d}<thresh1),$
        fitud(&i,3)+%dot(%xrow(sdn,&i),bootres),$
        fitud(&i,4)+%dot(%xrow(sup,&i),bootres))))
end do i
How could I amend the above in order to obtain FIR's that correspond to the regimes outlined below?

Code: Select all

set d1 = (thrfrml1{d}<thresh1)+2*(((thrfrml1{d}>=thresh1)*(thrfrml2{d}<thresh2))*(thrfrml3{d}<thresh3))+3*(((thrfrml1{d}>=thresh1)*(thrfrml2{d}<thresh2))*(thrfrml3{d}>=thresh3))
Best regards,

Juan
Attachments
tvar_estimate_4_estados_2variables_de_quiebre.RPF
(16.83 KiB) Downloaded 1071 times
pass_through27.rat
(38.75 KiB) Downloaded 1041 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Balke(2000) Threshold VAR

Unread post by TomDoan »

The FRML at the top lists four cases and the one at the bottom has only three. Certainly a simpler way to handle these is to use
  1. 1<
  2. 1> and 2>
  3. 1> and 2< and 3>
  4. 1> and 2< and 3<
as your four cases.
alvarezcc
Posts: 25
Joined: Wed Mar 25, 2009 8:59 am

Re: Balke(2000) Threshold VAR

Unread post by alvarezcc »

Hi Tom! When estimating threshold VAR models, what would you seggest to do for selecting the appropiate moving average order and lag for the delay parameter?

Thanks!!
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Balke(2000) Threshold VAR

Unread post by TomDoan »

The usual way to pick the delay is to choose the one that maximizes the test statistic. However, in this case, it's probably fairly obvious that the one period delay is the one supported by the theory underlying the model. As to the filter, there's no requirement that you use one at all. The only mention of this in the Balke paper is that the different lag lengths were chosen to give a similar level of autocorrelation (i.e. smoothness). Which doesn't explain what level of smoothness was the goal. I assume that the model didn't work as well with single quarter values, which might have been too volatile to give a good indication of the state of policy. If you have a threshold series which is naturally fairly smooth, you might want to just use it directly.
yizhuorui
Posts: 8
Joined: Tue Aug 23, 2016 4:17 am

Re: Balke(2000) Threshold VAR

Unread post by yizhuorui »

Dear tom,
I am confused about the "thrfrml" in the "tvar_irf" code all the time. In the paper of Balke(2000), the variable are d1y、d1p、money、credit.Why the "thrfrml" should be added to the "group" instruction and what does this "thrfrml" mean ?
Another question :) .Would it be possible to exist the generalized variance decomposition about the threshold var? Is generalized variance decomposition estimated in its respective regime rather than in a whole? And if generalized variance decomposition is estimated in its respective regime what should i do to modified the code?
Thanks!!!
YI
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Balke(2000) Threshold VAR

Unread post by TomDoan »

yizhuorui wrote:Dear tom,
I am confused about the "thrfrml" in the "tvar_irf" code all the time. In the paper of Balke(2000), the variable are d1y、d1p、money、credit.Why the "thrfrml" should be added to the "group" instruction and what does this "thrfrml" mean ?

Code: Select all

*
* This generates an equation (and from it a FRML) to compute the moving
* average of the data
*
dim macoeffs(malength)
comp macoeffs = %const(1./malength)
equation(identity,coeffs=macoeffs) threqn credthr
# credit{0 to malength-1}
frml(equation=threqn,identity) thrfrml
As you can see, THRFRML is an identity. Because the threshold variable is endogenous (a moving average of some form of the "credit" variable), it will also have to be generated as part of the simulations.
yizhuorui wrote: Another question :) .Would it be possible to exist the generalized variance decomposition about the threshold var? Is generalized variance decomposition estimated in its respective regime rather than in a whole? And if generalized variance decomposition is estimated in its respective regime what should i do to modified the code?
No. Aside from the fact that the "generalized variance decomposition" is a decomposition of a junk number, it doesn't exist in a threshold model anyway---it's a statistic for a fixed coefficient/fixed covariance matrix model.
yizhuorui
Posts: 8
Joined: Tue Aug 23, 2016 4:17 am

Re: Balke(2000) Threshold VAR

Unread post by yizhuorui »

Thanks tom, I am still a bit confused from your response. If my threshold is a 3 lags of credit rather than a moving average of some form of the "credit" variable,i am not sure weather the following code is correct:
frml(identity) thrfrml credit = credit{3}
and the group instruction will be :
group tvar tvarf(1) tvarf(2) tvarf(3) tvarf(4) thrfrml

Another problem is if my model is a near-var and how should i modify for the "sweep" instruction? for instance i assume "credit" equation only have 2 lags rather than 4 lags in the code of "tvar_estimate"
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Balke(2000) Threshold VAR

Unread post by TomDoan »

yizhuorui wrote:Thanks tom, I am still a bit confused from your response. If my threshold is a 3 lags of credit rather than a moving average of some form of the "credit" variable,i am not sure weather the following code is correct:
frml(identity) thrfrml credit = credit{3}
and the group instruction will be :
group tvar tvarf(1) tvarf(2) tvarf(3) tvarf(4) thrfrml
That's correct.
yizhuorui wrote: Another problem is if my model is a near-var and how should i modify for the "sweep" instruction? for instance i assume "credit" equation only have 2 lags rather than 4 lags in the code of "tvar_estimate"
You can't modify SWEEP for that. If it's a near-VAR, you have to use SUR with separate SMPL's for the subsamples and add up the %LOGL's to get the overall log likelihood. You might want to pick the threshold and test for the threshold effect using the full VAR, then (maybe) reduce to the near-VAR at the end.
yizhuorui
Posts: 8
Joined: Tue Aug 23, 2016 4:17 am

Re: Balke(2000) Threshold VAR

Unread post by yizhuorui »

Dear tom,
Thank you once again. Following your advice,i modified the code and the regarding code is :

Code: Select all

equation aa g3year
# constant g3year{1 to p} g3month{1 to p} 
equation bb g3month
# constant g3year{1 to p} g3month{1 to p}
set thresh = sspread{1}
@gridseries(from=-.30,to=.05,n=300,pts=ngrid) rgrid
set aic 1 ngrid = 0.0
set bic 1 ngrid = 0.0
set cic 1 ngrid = 0.0
compute bestaic=%na
do i=1,ngrid
   compute rtest=rgrid(i)
sur(noprint,nosigma,smpl=thresh<rtest) 2
# aa
# bb
   compute bic(i)=-2.0*%logl+2.0*30
sur(noprint,nosigma,smpl=thresh>rtest) 2
# aa
# bb
   compute cic(i)=-2.0*%logl+2.0*30
compute aic(i)=bic(i)+cic(i) 
if i==1.or.aic(i)<bestaic
      compute bestaic=aic(i),bestbreak=rtest
end do i
*scatter(footer="AIC Values for Interest Rates Regression vs Break Point")
# rgrid aic
disp "Best Break is" bestbreak "with AIC" bestaic
The code runs ok(this is tsay1998's example,the outcome of bestbreak and AIC is the same with original code while i change "var" option to "heter" in sweep instruction ).
However,when i add with some dummy variable ,for instance:

Code: Select all

dumny(ao=1970:01) dummy1
equation aa g3year
# constant g3year{1 to p} g3month{1 to p} dummy1
equation bb g3month
# constant g3year{1 to p} g3month{1 to p} dummy1
The output reveals "## REG13. Singular Regressions - Check for Collinearity among Rows 1 to 16.The Error Occurred At Location 132, Line 5 of loop/block".And then, i also add with dummy variable in sweep instruction of tsay1998's code,but it can run ok .what should i do to deal with this Collinearity? i dropped into the deep confusion once time :cry: :cry: :cry: :cry: :cry: :cry:
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Balke(2000) Threshold VAR

Unread post by TomDoan »

I'm asssuming that at least some of the partitions put all the data points in one side or other of the dummy, making it either all ones or all zeros, hence collinear.
yizhuorui
Posts: 8
Joined: Tue Aug 23, 2016 4:17 am

Re: Balke(2000) Threshold VAR

Unread post by yizhuorui »

Dear tom ,
I genuinely appreciate your help and support about the above questions.Although my modified threshold VAR(three regimes and one lag of WTI is threshold variable) runs OK , it seem to be the exact same output of GIRF under the different regimes(my attention are Girf(1)(2,1)、Girf(1)(3,1)、Girf(1)(4,1)、Girf(1)(5,1)). Therefore ,i dont't know the reason is date date-determined or my modified code ocuurs error because i am still not sure the thresholds' FRML instruction 、 GROUP instruction、PANEL instrution. I attached my code and data,could you help me check whether those instrction are correct?
Attachments
三体制不加虚拟变量.txt
(7.43 KiB) Downloaded 1138 times
199602开始差分汇率没用的x12.csv
(24.27 KiB) Downloaded 1115 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Balke(2000) Threshold VAR

Unread post by TomDoan »

You're not properly adapting this:

panel(group=d1{0},id=values,identries=entries) d1 rstart rend
{
if upper==2.and.values(1)==2.or.upper==1.and.values(1)==1.or.upper==0.and.values(1)==0
compute rdates=entries(1),nrep=%size(rdates)
else
compute rdates=entries(2),nrep=%size(rdates)
}

to three regimes. values and entries can (and will) have three possible values, and this won't ever pick entries(3) as rdates.

I would also note that other than your output and cpi series having rather strong (but very irregular) seasonals, none of your series have much correlation, so your IRF's even when you get this to work are likely to be spike followed by (near) zeros.
yizhuorui
Posts: 8
Joined: Tue Aug 23, 2016 4:17 am

Re: Balke(2000) Threshold VAR

Unread post by yizhuorui »

Thanks tom,
I seem to know what you mean,so i modify the panel instruction,as shown below.But i don't know if it is correct.
panel(group=d1{0},id=values,identries=entries) d1 rstart rend
{
if upper==2.and.values(3)==2 {
compute rdates=entries(3),nrep=%size(rdates)
}
else if upper==1.and.values(2)==1{
compute rdates=entries(2),nrep=%size(rdates)
}
else compute rdates=entries(1),nrep=%size(rdates)
}


Of course,due to the Chinese Spring Festival effect, X12 and X13 hardly deal with data of Chinese macro variables on January and February .So we often abandon the data in January and February or add with some dummy variables.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Balke(2000) Threshold VAR

Unread post by TomDoan »

panel(group=d1{0},id=values,identries=entries) d1 rstart rend
{
if upper==values(3)  {
   compute rdates=entries(3),nrep=%size(rdates)
}
else if upper==values(2) {
   compute rdates=entries(2),nrep=%size(rdates)
}
else
   compute rdates=entries(1),nrep=%size(rdates)
}
applej
Posts: 20
Joined: Thu May 14, 2015 9:17 am

Re: Balke(2000) Threshold VAR

Unread post by applej »

Dear Tom,
I did minor changes to the program, including nvar=5 and nkrep=100, etc. However, in the final GIRF simulation step, i.e."
infobox(action=define,lower=1,upper=nrep,progress) "Bootstrapping Across Initial Values"
do jrep=1,nrep
infobox(current=jrep)
* Copy observed data into depvar slots
compute basedate=rdates(jrep)
do i=1,nvar
set depvars(i) wstart-maxlag wstart-1 = data(i)(t-wstart+basedate)
end do i
* Loop over bootstrap replications
do krep=1,nkrep
* Generate the bootstrap shuffle
boot rentries wstart wend rstart rend
..."


I got the following errors:

" The Error Occurred At Location 488, Line 27 of loop/block
## FO8. Gauss-Seidel did not converge in 50 Iterations. Criterion = 1.000000.
The Error Occurred At Location 783, Line 40 of loop/block
## FO8. Gauss-Seidel did not converge in 50 Iterations. Criterion = 1.000000.

...

# FO8. Gauss-Seidel did not converge in 50 Iterations. Criterion = 0.601289.
The Error Occurred At Location 783, Line 40 of loop/block
...."

I'm hoping you could give me some suggestion the reason and how to fix it. Thank you! :D
Also, may I know how to show, for example the "location488", on the editor window?

Thank you,
J

program:
tvarirf_rrg.RPF
my tvarirf program
(11.4 KiB) Downloaded 1159 times
dataset:
rawdata6.csv
data set
(43.02 KiB) Downloaded 1157 times
Post Reply