Yes, the code works! but I'm not sure the result is correct.. In practice, what I am trying to do is to compare two VAR models. I have estimated one model with 6 variables, and the other one with 5 variables + an exogenous. (the 6 variables are the same).
I have then computed then IRFs, and calculated the difference btw IRFs of the two models
Next, I wanted to compute simulated IRFs' differences, so I have simulated data and re-estimated the 2 models. I have done 2000 replications.
For each replication, I then compared the maximum difference I get from the two simulated IRFs, with the difference between the 2 original IRFs.
But over 2000 replications, only once I got a simulated difference greater than the benchmark (original) difference.
Sorry, I have explained in a bad way, hope you understand.. here is the complete code:
D=max(abs(IP))
tcount=0
y = 8 13 12 1 2 3
y1 = 8 13 12 1 2
x = 3
#MODEL 1
var 6 y --silent
matrix Ac = $compan[1:6,]
matrix U = $uhat. +$coeff[1,]
#Initial values
matrix y0 = {var1, var2, var3, var4, var5, var6}[1:6,]
#MODEL 2
var 6 y1; x --silent
matrix Ac1 = $compan[1:5,]
matrix U1 = $uhat.+coeff[1,]
#Initial values
matrix y01={var1, var2, var3, var4, var5}[1:6,]
loop 2000
# Simulation data model 1
matrix Usim = resample (U)
matrix Ysim = varsimul(Ac, Usim, y0)
series frs=Ysim[,1]
series ips=Ysim[,2]
...
series bs=Ysim[,6]
# model 1 with simulated data
var 6 frs ips ... bs --silent
set horizon 60
matrix K = cholesky($sigma)
matrix V = $vma
#matrix of IRFs from simulated data
matrix IRFsim = V * (K**(I(6))
# IRF of variable of interest
matrix IRFip_b = IRFsim[,2]
# Simulation data model 2
matrix Usim1 = resample(U1)
matrix Ysim1 = varsimul(Ac1, Usim1, y01)
series frs1 = Ysim1[,1]
series ips1 = Ysim1[,2]
...
series fs1 = Ysim1[,5]
var 6 frs1 ips1 ... fs1; x --silent
set horizon 60
matrix K1 = cholesky($sigma)
matrix V1 = $vma
matrix IRFsim1 = V1 * (K1**I(5))
matrix IRFip_b1=IRFsim1[,2]
#Difference between IRFs from simulated models 1 and 2
matrix Diff = IRFip_b1 - IRFip_b
Dsim = max(abs(Diff))
if Dsim > D
tcount = tcount + 1
endif
endloop
print count
I would be very grateful if someone could provide any suggestion about it..
Thank you again,
Gabriela