"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "addons/SVAR/SVAR_signrestr_utils.inp" between
gretl-2020a.tar.xz and gretl-2020b.tar.xz

About: gretl (Gnu Regression, Econometrics and Time-series Library) is a cross-platform statistical package mainly for econometric analysis.

SVAR_signrestr_utils.inp  (gretl-2020a.tar.xz):SVAR_signrestr_utils.inp  (gretl-2020b.tar.xz)
# Utility functions for the sign restriction method in SVAR. # Utility functions for the sign restriction method in SVAR.
# (Later could probably merged into SVAR_utils.inp) # (Later could probably merged into SVAR_utils.inp)
############################# #############################
function void putIrf_to_accdraw(bundle *SVARobj, int whichdraw[0::0] )
# Only for SR (type 10)
# to transfer the IRFs to the old format
if SVARobj.type != 10
funcerr "this function only for SR type"
elif !inbundle(SVARobj, "acc_draws")
funcerr "need accepted draws (acc_draws)"
endif
n = SVARobj.n
h = SVARobj.horizon + 1
bundle pickdraw = SVARobj.acc_draws[whichdraw]
matrix IRFs = zeros(h, n*n)
loop ix = 1..h -q
IRFs[ix, ] = vec(pickdraw.irfs[ix])'
endloop
# copy to origin
matrix SVARobj.acc_draws[whichdraw].IRFs = IRFs
end function
###########################
function matrices muVARparE_mayberedr(const bundle Smod, matrix Bofonedraw[null] ) function matrices muVARparE_mayberedr(const bundle Smod, matrix Bofonedraw[null] )
# Retrieves all the quantities that perhaps are redrawn # Retrieves all the quantities that perhaps are redrawn
# in the Bayesian set id case: # in the Bayesian set id case:
# - mu: exog. coeffs, B[1:k , ] # - mu: exog. coeffs, B[1:k , ]
# - VARpar: autoregr. coeffs, B[k+1: ,] # - VARpar: autoregr. coeffs, B[k+1: ,]
# - E: residuals # - E: residuals
redrawn = 0 redrawn = 0
if Smod.type == 10 if Smod.type == 10
skipping to change at line 40 skipping to change at line 66
# need to use the resids associated with re-drawn coefficients # need to use the resids associated with re-drawn coefficients
matrix mu = Bofonedraw[1 : Smod.k ,] matrix mu = Bofonedraw[1 : Smod.k ,]
matrix VARpar = Bofonedraw[Smod.k + 1 : ,] matrix VARpar = Bofonedraw[Smod.k + 1 : ,]
matrix resids = Smod.Y[Smod.p + 1 : ,] - Smod.mreg * Bofonedraw matrix resids = Smod.Y[Smod.p + 1 : ,] - Smod.mreg * Bofonedraw
endif endif
return defarray(mu, VARpar, resids) return defarray(mu, VARpar, resids)
end function end function
function void errchkSRhisto(bundle *Smod, int drawix) function void errchkSRhisto(bundle *Smod, int drawix)
if !inbundle(Smod, "bestdraw")
funcerr "Model not properly initialized for SR type"
elif !Smod.bestdraw && !drawix
funcerr "Need to pick one particular draw (run SRgetbest?)"
if !Smod.storeSRirfs elif !Smod.storeSRirfs
funcerr "Need accepted draws content (acc_draws) in set-id case" funcerr "Need accepted draws content (acc_draws) in set-id case"
elif drawix == 0
funcerr "Need to pick one particular draw (index)"
elif drawix > nelem(Smod.acc_draws) elif drawix > nelem(Smod.acc_draws)
printf "Only %d accepted draws exist\n", nelem(Smod.acc_draws) printf "Only %d accepted draws exist\n", nelem(Smod.acc_draws)
funcerr "Draw index out of range" funcerr "Draw index out of range"
endif endif
end function end function
function void errmsgshockmatch(const matrix pos, string sname) function void errmsgshockmatch(const matrix pos, string sname)
if nelem(pos) != 1 if nelem(pos) != 1
printf "You don't have a shock named %s in your model.\n", sname printf "You don't have a shock named %s in your model.\n", sname
print " (or several ones)" print " (or several ones)"
funcerr "Specify correct and unique shock names" funcerr "Specify correct and unique shock names"
endif endif
end function end function
function strings getstrings_byindex(const strings S, const matrix indices)
# collects the (in general non-contiguous) sub-array
# indexed by indices (imitate fancy indexing)
strings out = null
matrix m = vec(indices)
loop i = 1..nelem(m) -q
out += S[m[i]]
endloop
return out
end function
# -------------------------------- # --------------------------------
function matrix names2indices(strings fromwhich, strings names) function matrix names2indices(strings fromwhich, strings names)
matrix which = {} matrix which = {}
if !nelem(names) # default, all if !nelem(names) # default, all
which = seq(1, nelem(fromwhich)) which = seq(1, nelem(fromwhich))
else else
loop n = 1..nelem(names) -q loop n = 1..nelem(names) -q
skipping to change at line 118 skipping to change at line 136
return n_exotic return n_exotic
end function end function
# ---------------------------------- # ----------------------------------
function void rot_redraw(bundle *b, const bundle mod, bool DO_BAYES, function void rot_redraw(bundle *b, const bundle mod, bool DO_BAYES,
const matrix B, const matrix B,
const matrix iXX ) const matrix iXX )
if DO_BAYES if DO_BAYES
matrices Mats = drawnormwis(iXX, B, mod.Sigma, b.df) matrices Mats = drawnormwis(iXX, B, mod.Sigma, b.df) # changed df at sou rce
matrix b.B = Mats[1] matrix b.B = Mats[1]
matrix b.Sigma = Mats[2] matrix b.Sigma = Mats[2]
endif endif
matrix b.rot = qrdecomp(mnormal(mod.n, mod.n)) matrix b.rot = qrdecomp(mnormal(mod.n, mod.n))
end function end function
# ----------------------------------- # -----------------------------------
skipping to change at line 270 skipping to change at line 288
endif endif
print noflip flip ret print noflip flip ret
endif endif
return ret return ret
end function end function
function matrix check_irfs(matrices M, matrix A, int verbose[0]) function matrix check_irfs(matrices M, matrix A, int verbose[0])
# Tag: sign restriction apparatus # Tag: sign restriction apparatus
# Here we examine the constraints on the IRFs we return a vector # Here we examine the constraints on the IRFs
# We return a vector
# indicating if all the constraints contained in the matrix A are # indicating if all the constraints contained in the matrix A are
# satisfied; each row of A contains # satisfied; each row of A contains
# #
# 1 : ordinal no of variable to check # 1 : ordinal no of variable to check
# 2, 3 : bounds (NA for +-infty) # 2, 3 : bounds (NA for +-infty)
# 4, 5 : IRF interval to check (0-based) # 4, 5 : IRF interval to check (0-based)
# #
# It may happen that the IRFs are ok up to a sign swap; we flag this # It may happen that the IRFs are ok up to a sign swap; we flag this
# case by setting the corresponding column to -1 # case by setting the corresponding column to -1
skipping to change at line 304 skipping to change at line 323
matrix positives = minc(chks) .= 1 matrix positives = minc(chks) .= 1
matrix negatives = maxc(chks) .= -1 matrix negatives = maxc(chks) .= -1
return positives - negatives return positives - negatives
end function end function
function scalar check_id(matrix id) function scalar check_id(matrix id)
# Tag: sign restriction apparatus # Tag: sign restriction apparatus
# Here we check if the sign check restriction allow us to # Here we check if the sign restrictions allow us to
# form a coherent set of IRFs for the problem at hand # form a coherent set of IRFs for the problem at hand
# #
# the input matrix is has r rows and c columns, where r is the # the input matrix has r rows and c columns, where r is the
# number of shocks we want to identify and c is the number # number of shocks we want to identify and c is the number
# of variables in the system; note that r can be smaller # of variables in the system; note that r can be smaller
# than c for partially identified models; for example, in Uhlig # than c for partially identified models; for example, in Uhlig
# (2005) KME, c = 6 but r = 1 (the monetary policy shock) # (2005) KME, c = 6 but r = 1 (the monetary policy shock)
# #
# id can only contain 0s, 1s and -1s; therefore, for completely # id can only contain 0s, 1s and -1s; therefore, for completely
# identified models, we just check if "id" is a proper orthogonal # identified models, we just check if "id" is a proper orthogonal
# matrix; for partially identified models, we need to make sure # matrix; for partially identified models, we need to make sure
# that we have only one non-zero entry for each row, and that # that we have only one non-zero entry for each row, and that
# the rank of id is r. # the rank of id is r.
 End of changes. 9 change blocks. 
18 lines changed or deleted 37 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)