Page 1 of 2
Simulate a VAR process
Posted: Thu Mar 28, 2024 2:39 pm
by ac_1
Hi Tom,
I am trying to simulate a VAR process and reproduce Figure 5.6 in Enders(2014) AETS. Unfortunately, the following does not work.
Code: Select all
compute nburn=100
compute nobs=100
compute sigma=1.0
set e1 1 nburn+nobs = %ran(sigma)
set e2 1 nburn+nobs = %ran(sigma)
compute a10=0.0
compute a11=+0.7
compute a12=+0.7
compute a20=0.0
compute a21=+0.2
compute a22=+0.2
set y 1 1 = 0.0
set z 1 1 = 0.0
set y 2 nburn+nobs = a10 + a11*y{1} + a12*z{1} + e1{0}
set z 2 nburn+nobs = a20 + a21*y{1} + a22*z{1} + e2{0}
Amarjit
Re: Simulate a VAR process
Posted: Thu Mar 28, 2024 10:48 pm
by TomDoan
Separate SETs won't work---you need to use SIMULATE since the two equations have to be solved at the same time.
Re: Simulate a VAR process
Posted: Fri Mar 29, 2024 5:46 am
by ac_1
TomDoan wrote: ↑Thu Mar 28, 2024 10:48 pm
Separate SETs won't work---you need to use SIMULATE since the two equations have to be solved at the same time.
An attempt at Figure 5.6 Panel(a). Correct?
Code: Select all
*===============================
seed %today()
allocate 150
compute a10=0.0
compute a11=+0.7
compute a12=+0.2
compute a20=0.0
compute a21=+0.2
compute a22=+0.7
set y = 0.0
set z = 0.0
equation(variance=1.0,coeffs=||a10,a11,a12||) vareq1 y
# constant y{1} z{1}
equation(variance=1.0,coeffs=||a20,a21,a22||) vareq2 z
# constant y{1} z{1}
group varmodel vareq1 vareq2
simulate(model=varmodel,results=simuls,from=2,steps=149)
prin 51 150 simuls(1) simuls(2)
graph(header="") 2
# simuls(1) 51 150
# simuls(2) 51 150
If I want to reproduce Figure 5.7 Panel(a) and Panel(b) I need to estimate the varmodel with the simulated series (the coeffs are 'different' from a10 to a22 which is probably due to the series being only 100 points). Also, the errors in equations y and z ought to be correlated at 0.8. How?
Code: Select all
*===============================
* Impulse Response
system(model=varmodel2)
variables simuls(1) simuls(2)
lags 1
det constant
end(system)
estimate(residuals=resids,noftests) 1 150
compute impsteps=20
dec vect[strings] implabels
compute implabels=|| "simuls(1)", "simuls(2)"||
impulse(model=varmodel,steps=impsteps,results=impulses)
@varirf(model=varmodel,steps=impsteps,varlabels=implabels,page=byvariables,errors)
Re: Simulate a VAR process
Posted: Fri Mar 29, 2024 8:20 am
by TomDoan
That's what the CV option on SIMULATE is for. See the rollingcausality.rpf program.
Re: Simulate a VAR process
Posted: Mon Apr 08, 2024 5:20 am
by ac_1
Maybe this needs a new topic, but it's the on same theme generating simulations to gain intuition. Here's an attempt at simulating a 3 variable cointegrated system (using the method in enders4p375.rpf) -- it very much depends on the choice of coefficients (these just happen to be symmetric). Correct?
Code: Select all
set eps1 = %ran(1)
set eps2 = %ran(1)
set eps3 = %ran(1)
clear(zeros) y z w
* Random walk + noise processes
frml yeq y = .5*y{1}+.2*z{1}+.3*w{1}+eps1
frml zeq z = .4*y{1}+.1*z{1}+.2*w{1}+eps2
frml weq w = .3*y{1}+.2*z{1}+.3*w{1}+eps3
group cointmodel yeq>>y zeq>>z weq>>w
forecast(model=cointmodel,from=2,to=nsteps)
And using the SIMULATE method as in RollingCausality.rpf for a non cointegrated system due to the choice of coefficients, and not neccessarily because s12=0. Correct?
Code: Select all
* Random walk processes
compute a10=0.0
compute a11=+0.8
compute a12=+0.5
compute a20=0.0
compute a21=+0.2
compute a22=+0.1
* covariance matrix of shocks: eps1 and eps2
compute s11=1.0
compute s12=0.0
compute s22=1.0
set eps1 = %ran(1)
set eps2 = %ran(1)
set y 1 nsteps = 0.0
set z 1 nsteps = 0.0
equation(coeffs=||a10,a11,a12,1.0||) vareq1 y
# constant y{1} z{1} eps1
equation(coeffs=||a20,a21,a22,1.0||) vareq2 z
# constant y{1} z{1} eps2
group varmodel vareq1 vareq2
compute [symm] sigma=||s11|s12,s22||
simulate(model=varmodel,results=simuls,from=2,steps=nsteps,cv=sigma)
Re: Simulate a VAR process
Posted: Mon Apr 08, 2024 7:05 am
by TomDoan
The covariance matrix has no effect on the unit root/cointegration behavior of the series.
Your first example is very much NOT a cointegrated process---the series are all stationary. Yes, it depends upon the coefficients, and it is very difficult to look at the coefficients and tell anything about it. (Just because the lag coefficients across series sum to one means nothing.).
Re: Simulate a VAR process
Posted: Tue Apr 09, 2024 3:32 am
by ac_1
TomDoan wrote: ↑Mon Apr 08, 2024 7:05 am
The covariance matrix has no effect on the unit root/cointegration behavior of the series.
Your first example is very much NOT a cointegrated process---the series are all stationary. Yes, it depends upon the coefficients, and it is very difficult to look at the coefficients and tell anything about it. (Just because the lag coefficients across series sum to one means nothing.).
Why are the lag coeffiecients in enders4p375.rpf summing to 1.0?
frml yeq y = ydrift+.8*y{1}+.2*z{1}+eps1
frml zeq z = zdrift+.2*y{1}+.8*z{1}+eps2
I'm aiming to simulate a 3 variable cointegrated system, constructed so that I may choose which series are cointegrated and which are not.
Using the RollingCausality.rpf (SIMULATE) method, without CV, instead.
The y series lag coefficients sum to 0.9, z and w series each sum to 1. All series are I(1), and (I think) some are cointegrated as per ADF tests i.e. not all equilibrium error's are I(0). In otherwords, what is the appropriate choice for the coeffcients as the simulation is sensitive to the seed and nsteps?
Code: Select all
*===============================
seed 1
compute nsteps=150
allocate nsteps
*===============================
* Random walk processes
compute a10=0.0
compute a11=+0.4
compute a12=+0.3
compute a13=+0.2
compute a20=0.0
compute a21=+0.5
compute a22=+0.3
compute a23=+0.2
compute a30=0.0
compute a31=+0.3
compute a32=+0.5
compute a33=+0.2
set eps1 = %ran(1)
set eps2 = %ran(1)
set eps3 = %ran(1)
set y 1 nsteps = 0.0
set z 1 nsteps = 0.0
set w 1 nsteps = 0.0
equation(variance=1,coeffs=||a10,a11,a12,a13,1.0||) vareq1 y
# constant y{1} z{1} w{1} eps1
equation(variance=1,coeffs=||a20,a21,a22,a23,1.0||) vareq2 z
# constant y{1} z{1} w{1} eps2
equation(variance=1,coeffs=||a30,a31,a32,a33,1.0||) vareq3 w
# constant y{1} z{1} w{1} eps3
group cointmodel vareq1 vareq2 vareq3
simulate(model=cointmodel,results=simuls,from=2,steps=(nsteps-1))
prin / simuls(1) simuls(2) simuls(3)
* characteristic roots
compute companion=%modelcompanion(cointmodel)
eigen(cvalues=cv) companion
disp cv
*===============================
* Dickey-Fuller tests
*
@dfunit(det=trend,maxlags=10,method=aic) simuls(1) 101 nsteps
@dfunit(det=trend,maxlags=10,method=aic) simuls(2) 101 nsteps
@dfunit(det=trend,maxlags=10,method=aic) simuls(3) 101 nsteps
@dfunit(det=constant,maxlags=10,method=aic) simuls(1) 101 nsteps
@dfunit(det=constant,maxlags=10,method=aic) simuls(2) 101 nsteps
@dfunit(det=constant,maxlags=10,method=aic) simuls(3) 101 nsteps
set eqerror = simuls(1)-simuls(2)
set eqerror = simuls(1)-simuls(3)
set eqerror = simuls(1)+simuls(2)-simuls(3)
set eqerror = simuls(1)-simuls(2)-simuls(3)
set eqerror = simuls(1)-simuls(2)+simuls(3)
@dfunit(det=trend,maxlags=10,method=aic) eqerror 101 nsteps
@dfunit(det=constant,maxlags=10,method=aic) eqerror 101 nsteps
Re: Simulate a VAR process
Posted: Tue Apr 09, 2024 8:00 am
by TomDoan
If the coefficients in ALL equations sum to 1 then you have at least one unit root. Your first example had that happening only in a single equation, which tells you precisely nothing. If coefficients in all equations sum to 1, you have a cointegrated process with very specific cointegrating vectors. (In the 2 variable case, (x-y) is stationary if the cross coefficients aren't zero). Note that this means that if the process is cointegrated with something other than x-y, the coefficients will NOT sum to one.
To simulate a more general cointegrated process, it's easiest to use a VECM setup: the right side is the lag of the dependent variable, terms in differences and loadings on the cointegrating vector(s). This, for instance, has x and y cointegrated with x-y being stationary.
Code: Select all
all 500
clear(zeros) x y
frml xeq x = x{1}+.3*(x{1}-x{2})-.2*(y{1}-y{2})-.5*(x{1}-y{1})
frml yeq y = y{1}-.2*(x{1}-x{2})+.4*(y{1}-y{2})+.3*(x{1}-y{1})
group xycoint xeq>>x yeq>>y
simulate(cv=||1.0|0.5,1.0||,model=xycoint,from=3,steps=498)
Re: Simulate a VAR process
Posted: Wed Apr 10, 2024 8:07 am
by TomDoan
ac_1 wrote: ↑Tue Apr 09, 2024 3:32 am
TomDoan wrote: ↑Mon Apr 08, 2024 7:05 am
The covariance matrix has no effect on the unit root/cointegration behavior of the series.
Your first example is very much NOT a cointegrated process---the series are all stationary. Yes, it depends upon the coefficients, and it is very difficult to look at the coefficients and tell anything about it. (Just because the lag coefficients across series sum to one means nothing.).
Why are the lag coeffiecients in enders4p375.rpf summing to 1.0?
frml yeq y = ydrift+.8*y{1}+.2*z{1}+eps1
frml zeq z = zdrift+.2*y{1}+.8*z{1}+eps2
I'm aiming to simulate a 3 variable cointegrated system, constructed so that I may choose which series are cointegrated and which are not.
Using the RollingCausality.rpf (SIMULATE) method, without CV, instead.
The y series lag coefficients sum to 0.9, z and w series each sum to 1. All series are I(1), and (I think) some are cointegrated as per ADF tests i.e. not all equilibrium error's are I(0). In otherwords, what is the appropriate choice for the coeffcients as the simulation is sensitive to the seed and nsteps?
Your roots are:
( 0.95664, 0.00000) ( -0.02832, 0.05813) ( -0.02832, -0.05813)
Since that's for the theoretical model (not the estimated one), the series are not cointegrated because they are not integrated at all. .95664 may be close enough to 1 that in a sample of size 150, it may pass some tests for unit root, but it wouldn't if the sample were larger.
Re: Simulate a VAR process
Posted: Tue Apr 16, 2024 3:18 am
by ac_1
In a 3-variable system I have
Code: Select all
all 500
clear(zeros) x y z
frml xeq x = x{1}+.3*(x{1}-x{2})-.2*(y{1}-y{2})-.2*(z{1}-z{2})-.1*(x{1}+y{1}-z{1})
frml yeq y = y{1}-.2*(x{1}-x{2})+.4*(y{1}-y{2})-.1*(z{1}-z{2})+.1*(x{1}+y{1}-z{1})
frml zeq z = z{1}-.1*(x{1}-x{2})+.1*(y{1}-y{2})+.1*(z{1}-z{2})+.1*(x{1}+y{1}-z{1})
group xycoint xeq>>x yeq>>y zeq>>z
compute [symm] sigma=||1.0|0.5,1.0|0.5,0.5,1.0||
disp sigma
simulate(cv=sigma,model=xycoint,from=3,steps=498)
The vector (x+y-z) is stationary, no others are by construction including the 2 variable realtionships: (x,y), (x,z), (y,z). Correct?
How does this relate to ECT's, where the
full set considers just the 3-variable relationship (x,y,z) not 2 variables?
Re: Simulate a VAR process
Posted: Tue Apr 16, 2024 7:03 am
by TomDoan
I'm not sure what you're asking. If you do the pairwise VECM's, none of the pairs will be cointegrated. (x,y) omits z, so any linear combination of x and y is still non-stationary, etc; similarly for all other pairs.
Re: Simulate a VAR process
Posted: Wed Apr 17, 2024 1:18 am
by ac_1
TomDoan wrote: ↑Tue Apr 16, 2024 7:03 am
I'm not sure what you're asking. If you do the pairwise VECM's, none of the pairs will be cointegrated. (x,y) omits z, so any linear combination of x and y is still non-stationary, etc; similarly for all other pairs.
Sorry, in a 3-variable system, I can only have these (stationary) cointegrating vector(s), in each equation
x+y-z
x-y+z
x-y-z
on the RHS, and those are the full set ECT's.
And the pairwise
x-y
x-z
are not ECT's with 3-variables.
Correct?
Re: Simulate a VAR process
Posted: Wed Apr 17, 2024 6:34 am
by TomDoan
Your question makes no sense. Any linear combination of the three series can be stationary. If you wrote the program above with just x{1}-y{1} in the final terms, then x and y would be cointegrated and z would be integrated but not cointegrated with the other two. And, of course, there is no reason for the coefficients to be just +/- 1; it's just that those tend to come up naturally in theoretical relationships among economic variables.
Re: Simulate a VAR process
Posted: Thu Apr 18, 2024 3:23 am
by ac_1
TomDoan wrote: ↑Wed Apr 17, 2024 6:34 am
Your question makes no sense.
Any linear combination of the three series can be stationary. If you wrote the program above with just x{1}-y{1} in the final terms, then x and y would be cointegrated and z would be integrated but not cointegrated with the other two. And, of course, there is no reason for the coefficients to be just +/- 1; it's just that those tend to come up naturally in theoretical relationships among economic variables.
Simulating
multiple cointegrating vectors, question: can Johansen can find those?
Code: Select all
seed 1
frml xeq x = x{1}+.1*(x{1}-x{2})-.2*(y{1}-y{2})-.2*(z{1}-z{2})-.05*(x{1}+y{1}-z{1})-.001*(x{1}-y{1})
frml yeq y = y{1}-.2*(x{1}-x{2})+.4*(y{1}-y{2})-.1*(z{1}-z{2})+.001*(x{1}+y{1}-z{1})+.5*(x{1}-y{1})
frml zeq z = z{1}-.1*(x{1}-x{2})+.1*(y{1}-y{2})+.1*(z{1}-z{2})+.01*(x{1}+y{1}-z{1})-.001*(x{1}-y{1})
x, y, z are I(1), and x+y-z, x-y are I(0); via ADF.
From
Code: Select all
@johmle(det=none,lags=1,vectors=evectors,eigenvalues=evalues)
# x y z
disp "vectors:" evectors
disp "eigenvalues:" evalues
there are two significant ECT''s:
Code: Select all
Unrestricted eigenvalues and -T log(1-lambda)
Rank EigVal Lambda-max Trace Trace-95% LogL
0 -2246.1790
1 0.4362 285.9527 354.9238 24.2100 -2103.2026
2 0.1279 68.2705 68.9711 12.2800 -2069.0674
3 0.0014 0.7006 0.7006 4.0700 -2068.7171
Cointegrating Vector for Largest Eigenvalue
X Y Z
-0.606748 0.542142 0.036138
VECTORS:
-0.60675 -0.33690 0.02750
0.54214 -0.18119 -0.01235
0.03614 0.26338 0.06692
EIGENVALUES: 0.43620 0.12787 0.00140
How does the eigenvectors, or additional information needed, relate to the simulated data?
And I'm still puzzled, in generating the simulated data there could be numerous I(0) combinations possible in the final term(s), based on that why in a 3 variable system does Johansen (can only) identify a maximum 3 equations for the full set ECT's?
Re: Simulate a VAR process
Posted: Thu Apr 18, 2024 7:10 am
by TomDoan
You need to do a lot more reading on cointegration. When the rank is 2 or more, there are an infinite number of possible cointegrating vectors. If (x+y-z) and (x-y) are stationary, then so is any linear combination of (x+y-z) and (x-y). The procedure gives a full breakdown of the PI matrix. You have to determine the rank and determine what the cointegrating space is from there. For forecasting or any related purposes, it doesn't matter how you normalize multiple cointegrating vectors---whatever you might do to the betas is washed out by the inverse transformation in the alphas.