// Path
// Setting the path
cd "h:\Stata"
// Load data
use ffr_gdp, clear
// Generate the change of 12-months treasury bills (variable t12)
gen rate=d.t12
// Do simple (reduced-form) var (with 3 lags)
var rate gdp, lags(1/3)
// checking VAR lag order
varsoc rate gdp // ,maxlag(8) // option for maximum lag order
// Checking stability condition of (S)VAR run command "varstable" after estimation of VAR
varstable
// "varwle" computes Wald tests to determine whether certain lags can be excluded
// "varlmar" checks for autocorrelation in the disturbances
/* IRFs
Stata’s irf commands can compute five types of IRFs:
- simple IRFs,
- orthogonalized IRFs,
- cumulative IRFs,
- cumulative orthogonalized IRFs and
- structural IRFs.
Use "irf create name, set(name_file)" to estimate the IRFs and FEVDs and store them as "name" in file name_file.irf after estimating a var
Use "irf graph" ; "irf table" to examine results
To do table of both irf (oirf and cumulated) measures do "irf table oirf coirf"
*/
// we have total k^2 IRD for k-variable VAR
// oirf means orthogonalized IRF (which is computed using Cholesky-decomposition so our short-term restriction)
var rate gdp, lags(1/3)
irf create var1, set(myirf1)
irf graph oirf, impulse(gdp) response(rate)
irf graph oirf, impulse(gdp) response(gdp)
irf graph oirf, impulse(rate) response(rate)
irf graph oirf, impulse(rate) response(gdp)
irf graph oirf
irf table oirf coirf, impulse(gdp) response(rate) noci stderrer //option noci removes confidence interval from the table
irf graph oirf coirf, impulse(gdp) response(rate) lstep(1) scheme(s2mono) // option lstep(x) - which step to start the figure/table from
/*
If ordering is arbitraty (i.e. not driven by economic theory), we can consider stability of results exploring the OIRFs resulting from a different ordering.
We can use option "order(gdp rate)" to change order of variables in VAR in "irf create"
*/
/*
The forecast error variance decomposition (FEVD)
*/
// "varbasic" fits a simple reduced-form VAR without constraints and graph the impulse-response functions (IRFs) (saved in file _varvbasic.irf).
// "varbasic varlist " command does VAR for variables "varlist" with default number of 2 lags
// "varbasic varlist, lags(1 2 3 4)" (or ", lags1/4") would do VAR(4)
// by default the series of orthogonalized IRFs (OIRFs) for 8 steps is produced; adding option ", step(12)" chages the IRF legngth to 12
// putting rate first we assume that shock to interest rate will affect both rate and GDP but shock to GDP will not affect rate contemporaneously
varbasic rate gdp, lags(1/3)
// If we want to add exogenous variable "exo_var" to the system add option ", exog(exo_var)"
// Command "testparm exo_var" tests joint significance of coefficients of that variable
// Command "vargranger" does block of Granger causality tests
// For structural var use svar command
/*
svar allows to estimate a model with a different set of assumptions than simple ordering/Cholesky decomposition of variance-covariance matrix Omega
For the short-term identification, it is done by specific assumption can be imposed on matrix A and B in equation
B e_t = A epsilon_t
This type of equation allows us to make assumptions on both variance of the structural shocks (A=/I but var(epislon) = 1 ) as well as matrix of coefficients (B).
By making matrix A lower diagonal and matrix B diagonal we impose our short-run restriction.
The command is of the form
svar dependent_variables, aeq(A) beq(B)
The long run restruction is estimated with command
svar dependent_variables, lreq(C)
where C is a matrix with long-run restriction
*/
// To define this matrices (and effectively impose restrictions) use command
matrix A = (1,0\ .,1) //"." implies lack of restrction -> this matrix denotes lower triangular matrix with 1 on the diagonal
matrix B = (.,0\ 0,.) // -> this is a diagonal matrix
//Then short run restriction are estimated with
svar rate gdp , aeq(A) beq(B)
// STATA stores the estimated residuals in e(Sigma)
// To get the cholesky decomposition use
matrix sig_var = e(Sigma)
matrix chol_var = cholesky(sig_var)
// Granger causality can be checked using command vargranger
quietly var rate gdp, lags(1/3)
vargranger // The null hypothesis is that variable 1 does not Granger causes variable 2