# Example script for mixed restrictions in gretl's SVAR addon set verbose off set plot_collection on set seed 240523 include SVAR.gfn ### artificial example nulldata 360 setobs 12 1:1 ### # set up the DGP (a trivariate VAR(1)) ### # the autoregresive matrix A = {0.8, -0.1, 0.1; 0.4, 0.8, -0.1; -0.4, 0.1, 0.8} # the true C matrix C = {1, 1, 0; -0.2, 1, 0.6; -0.8, 0.0, 1} scalar n = rows(C) E = mnormal($nobs, n) * C' # stationarity check eval eigen(A) M = C i = 0 if 1 printf "True IRFS:\n" loop 6 printf "%d:\n%8.3f\n", i, M M = A*M i++ endloop printf "%d:\n%8.3f\n", i, M endif # generate artificial data mY = varsimul(A, E, zeros(1, n)) list Y = mat2list(mY[2:,], "y") # var 1 Y --silent # eval $sigma # eval C*C' # set up the model list W = const scalar order = 1 scalar store_draws = 1 bundle mod = SVAR_setup("SR", Y, W, order, store_draws) # set up the sign restictions mod.snames = defarray("foo", "bar", "baz") # instantaneous restrictions mod.SRest = {} SVAR_SRplain(&mod, "y1", "foo", "+") SVAR_SRplain(&mod, "y2", "bar", "+") SVAR_SRplain(&mod, "y3", "baz", "+") SVAR_SRplain(&mod, "y2", "baz", "+", 4, 0) SVAR_SRplain(&mod, "y2", "foo", "-") SVAR_SRplain(&mod, "y1", "bar", "+", 4) SVAR_SRplain(&mod, "y3", "foo", "-", 4) # now add zero restrictions SVAR_restrict(&mod, "C", 1, 3) # instantaneous response of y1 to baz is 0 SVAR_restrict(&mod, "C", 3, 2) # instantaneous response of y3 to bar is 0 # add a cross-variable restriction, that is C_{1,2} = C_{2,2} # Rd = mod.Rd1 # tmp = {0,1,0; 0,-1,0; 0,0,0} # Rd = Rd | (vec(tmp)' ~ 0) # mod.Rd1 = Rd # estimate DO_BAYES = 1 SVAR_SRdraw(&mod, 192, DO_BAYES) # draw the IRFs strings IRFPlots SVAR_SRirf(mod, mod.Ynames, defarray("foo", "bar", "baz"), 0, &IRFPlots) gridplot IRFPlots --output=display # draw the spaghetti plots for the point restrictions SVAR_spagplot(mod, "y1", "baz") SVAR_spagplot(mod, "y3", "bar")