Aptech Store

Estimating SVAR Models With GAUSS

Introduction

Structural Vector Autoregressive (SVAR) models provide a structured approach to modeling dynamics and understanding the relationships between multiple time series variables. Their ability to capture complex interactions among multiple endogenous variables makes SVAR models fundamental tools in economics and finance. However, traditional software for estimating SVAR models has often been complicated, making analysis difficult to perform and interpret.

In today's blog, we present a step-by-step guide to using the new GAUSS procedure, svarFit, introduced in TSMT 4.0.

Understanding SVAR Models

A Structural Vector Autoregression (SVAR) model extends the basic Vector Autoregression (VAR) model by incorporating economic theory through restrictions that help identify structural shocks. This added structure allows analysts to understand how unexpected changes (shocks) in one variable impact others within the system over time.

Reduced Form vs. Structural Form

  • Reduced Form: Represents observable relationships without assumptions about the underlying economic structure. This form is purely data-driven and descriptive.
  • Structural Form: Applies economic theory through restrictions, enabling the identification of structural shocks. This form provides deeper insights into causal relationships.

Types of Restrictions

Restriction Description Example
Short-run Restrictions Assume certain immediate relationships between variables. A monetary policy shock affects interest rates instantly but impacts inflation with a delay.
Long-run Restrictions Impose conditions on the variables' behavior in the long term. Monetary policy does not have a long-term effect on real GDP.
Sign Restrictions Constrain the direction of variables' responses to shocks. A positive supply shock decreases inflation and increases output.

The svarFit Procedure

The svarFit procedure is an all-in-one tool for estimating SVAR models. It provides a streamlined approach to specifying, estimating, and analyzing SVAR models in GAUSS. With svarFit, you can:

  1. Estimate the reduced form VAR model.
  2. Apply short-run, long-run, or sign restrictions to identify structural shocks.
  3. Analyze dynamics through Impulse Response Functions (IRF), Forecast Error Variance Decomposition (FEVD), and Historical Decompositions (HD).
  4. Bootstrap confidence intervals to make statistical inferences with greater reliability.

General Usage

sOut = svarFit(data, formula [, ident, const, lags, ctl])
sOut = svarFit(Y [, X_exog, ident, const, lags, ctl])

data
String or dataframe, filename or dataframe to be used with formula string.
formula
String, model formula string.
Y
TxM or Tx(M+1) time series data. May include date variable, which will be removed from the data matrix and is not included in the model as a regressor.
X_exog
Optional, matrix or dataframe, exogenous variables. If specified, the model is estimated as a VARX model. The exogenous variables are assumed to be stationary and are included in the model as additional regressors. May include a date variable, which will be removed from the data matrix and is not included in the model as a regressor.
ident
Optional, string, the identification method. Options include: "oir" = zero short-run restrictions, "bq" = zero long-run restrictions, "sign" = sign restrictions.
const
Optional, scalar, specifying deterministic components of model. 0 = No constant or trend, 1 = Constant, 2 = Constant and trend. Default = 1.
lags
Optional, scalar, number of lags to include in VAR model. If not specified, optimal lags will be computed using the information criterion specified in ctl.ic.
ctl
Optional, an instance of the svarControl structure used for setting advanced controls for estimation.

Specifying the Model

The svarFit is fully compatible with GAUSS dataframes, allowing for intuitive model specification using formula strings. This makes it easy to set up and estimate VAR models directly from your data.

For example, suppose we want to model the relationship between GDP Growth Rate (GR_GDP) and Inflation Rate (IR) over time. A VAR(2) model with two lags can be represented mathematically as follows:

GR_GDPt=c1+a11GR_GDPt1+a12IRt1+a13GR_GDPt2+a14IRt2+u1tIRt=c2+a21GR_GDPt1+a22IRt1+a23GR_GDPt2+a24IRt2+u2t

Assume that our data is already loaded into a GAUSS dataframe, econ_data. This model can be directly specified for estimation using a formula string:

// Estimate SVAR model
call svarFit(econ_data, "GR_GDP + IR");

Now, let's extend our model by including an exogenous variable, interest rate (INT), to this model. Our extended VAR(2) model equations are updated as follows:

GR_GDPt=c1+a11GR_GDPt1+a12IRt1+a13GR_GDPt2+a14IRt2+b1INTt+u1tIRt=c2+a21GR_GDPt1+a22IRt1+a23GR_GDPt2+a24IRt2+b2INTt+u2t

To include this exogenous variable in our model specification, we simply update the formula string using the "~" symbol:

// Estimate model
call svarFit(econ_data, "GR_GDP + IR ~ INT");

Storing Results with svarOut

When we estimate SVAR models using svarFit, the results are stored in an svarOut structure. This structure is designed for intuitive access to key outputs, such as model coefficients, residuals, IRFs, and more.

// Declare output structure
struct svarOut sOut;
// Estimate model
sOut = svarFit(econ_data, "GR_GDP + IR ~ INT");

Beyond storing results, the svarOut structure is used for many post-estimation functions, such as plotIRF, plotFEVD and plotHD.

Key Members of svarOut

Component Description Example Usage
sOut.coefficients Estimated coefficients of the model. print sOut.coefficients;
sOut.residuals Residuals of the VAR equations, representing the portion not explained by the model. print sOut.residuals;
sOut.yhat In-sample predicted values of the dependent variables. print sOut.yhat;
sOut.sigma Covariance matrix of the residuals. print sOut.sigma;
sOut.irf Impulse Response Functions (IRFs) for analyzing the effects of shocks over time. plotIRF(sOut.irf);
sOut.fevd Forecast Error Variance Decomposition (FEVD) to evaluate the contribution of each shock to forecast errors. print sOut.fevd;
sOut.HD Historical Decompositions to analyze historical contributions of shocks. print sOut.HD;
sOut.aic, sOut.sbc Model selection criteria: Akaike Information Criterion (AIC) and Schwarz Bayesian Criterion (SBC). print sOut.aic;

Example One: Applying Short Run Restrictions

As a first example, let's start with the default behavior of svarFit, which is to estimate Short-Run Restrictions.

Short-Run Restrictions:

  • Assume that certain relationships between variables are instantaneous.
  • Are useful for modeling the immediate impacts of economic shocks, such as changes in interest rates or policy decisions.
  • Rely on a lower triangular matrix (Cholesky decomposition), which implies that variable ordering matters.

Loading Our Data

In this example, we will apply short-run restrictions to a VAR model with three endogenous variables: Inflation (Inflat), Unemployment (Unempl), and the Federal Funds Rate (Fedfund).

First, we load the dataset from the file "data_shortrun.dta" and specify our formula string:

/*
** Load data
*/
fname = "data_shortrun.dta";
data_shortrun = loadd(fname);
// Specify model formula string
// Three endogenous variable
// No exogenous variables
formula = "Inflat + Unempl + Fedfunds";

In this case the order of the variables in the formula string implies:

  • Inflat affects Unempl and Fedfunds contemporaneously.
  • Unempl affects Fedfunds but not Inflat contemporaneously.
  • Fedfunds does not affect the other variables contemporaneously.

Estimating Default Model

If we want to use model defaults, this is all we need to setup prior to estimation.

// Declare output structure
// for storing results
struct svarOut sOut;
// Estimate model with defaults
sOut = svarFit(data_shortrun, formula);

The svarFit procedure prints the reduced-form estimates:

=====================================================================================================
Model:                      SVAR(6)                               Number of Eqs.:                   3
Time Span:              1960-01-01:                               Valid cases:                    158
2000-10-01                                                                   
Log Likelihood:            -344.893                               AIC:                         -3.464
SBC:                         -2.418
=====================================================================================================
Equation                             R-sq                  DW                 SSE                RMSE
Inflat                            0.86474             1.93244           129.75134             0.96616 
Unempl                            0.98083             7.89061             7.05807             0.22534 
Fedfunds                          0.93764             2.81940            97.09873             0.83579 
=====================================================================================================
Results for reduced form equation Inflat
=====================================================================================================
Coefficient            Estimate           Std. Err.             T-Ratio          Prob |>| t
-----------------------------------------------------------------------------------------------------
Constant             0.78598             0.39276             2.00116             0.04732 
Inflat L(1)             0.61478             0.08430             7.29320             0.00000 
Unempl L(1)            -1.20719             0.40464            -2.98335             0.00337 
Fedfunds L(1)             0.12674             0.10292             1.23142             0.22024 
Inflat L(2)             0.08949             0.09798             0.91339             0.36262 
Unempl L(2)             2.17171             0.66854             3.24845             0.00146 
Fedfunds L(2)            -0.05198             0.13968            -0.37216             0.71034 
Inflat L(3)             0.04730             0.09946             0.47556             0.63514 
Unempl L(3)            -1.01991             0.70890            -1.43872             0.15248 
Fedfunds L(3)             0.02764             0.14328             0.19292             0.84731 
Inflat L(4)             0.18545             0.09767             1.89877             0.05967 
Unempl L(4)            -0.95056             0.70881            -1.34106             0.18209 
Fedfunds L(4)            -0.11887             0.14160            -0.83945             0.40266 
Inflat L(5)            -0.07630             0.09902            -0.77052             0.44230 
Unempl L(5)             1.07985             0.68944             1.56628             0.11956 
Fedfunds L(5)             0.14800             0.13465             1.09912             0.27361 
Inflat L(6)             0.14879             0.08763             1.69800             0.09174 
Unempl L(6)            -0.17321             0.38210            -0.45330             0.65104 
Fedfunds L(6)            -0.16674             0.10030            -1.66238             0.09869 
=====================================================================================================
Results for reduced form equation Unempl
=====================================================================================================
Coefficient            Estimate           Std. Err.             T-Ratio          Prob |>| t
-----------------------------------------------------------------------------------------------------
Constant             0.05439             0.09160             0.59376             0.55364 
Inflat L(1)             0.04011             0.01966             2.03992             0.04325 
Unempl L(1)             1.47354             0.09438            15.61362             0.00000 
Fedfunds L(1)            -0.00510             0.02400            -0.21231             0.83218 
Inflat L(2)            -0.02196             0.02285            -0.96086             0.33829 
Unempl L(2)            -0.52754             0.15592            -3.38329             0.00093 
Fedfunds L(2)             0.06812             0.03258             2.09107             0.03834 
Inflat L(3)             0.00214             0.02320             0.09211             0.92674 
Unempl L(3)             0.10859             0.16534             0.65680             0.51239 
Fedfunds L(3)            -0.04923             0.03342            -1.47314             0.14297 
Inflat L(4)            -0.02574             0.02278            -1.12973             0.26053 
Unempl L(4)            -0.32361             0.16532            -1.95752             0.05229 
Fedfunds L(4)             0.03248             0.03303             0.98338             0.32713 
Inflat L(5)             0.02071             0.02309             0.89691             0.37132 
Unempl L(5)             0.36505             0.16080             2.27026             0.02473 
Fedfunds L(5)            -0.01161             0.03141            -0.36975             0.71213 
Inflat L(6)            -0.00669             0.02044            -0.32745             0.74382 
Unempl L(6)            -0.14897             0.08912            -1.67160             0.09685 
Fedfunds L(6)            -0.00212             0.02339            -0.09070             0.92786 
=====================================================================================================
Results for reduced form equation Fedfunds
=====================================================================================================
Coefficient            Estimate           Std. Err.             T-Ratio          Prob |>| t
-----------------------------------------------------------------------------------------------------
Constant             0.28877             0.33977             0.84990             0.39684 
Inflat L(1)             0.05831             0.07292             0.79960             0.42530 
Unempl L(1)            -1.93356             0.35004            -5.52374             0.00000 
Fedfunds L(1)             0.93246             0.08903            10.47324             0.00000 
Inflat L(2)             0.22166             0.08476             2.61524             0.00990 
Unempl L(2)             2.17717             0.57833             3.76457             0.00025 
Fedfunds L(2)            -0.37931             0.12083            -3.13915             0.00207 
Inflat L(3)            -0.08237             0.08604            -0.95729             0.34008 
Unempl L(3)            -0.96474             0.61325            -1.57317             0.11795 
Fedfunds L(3)             0.53848             0.12395             4.34438             0.00003 
Inflat L(4)            -0.00264             0.08449            -0.03123             0.97513 
Unempl L(4)             1.41077             0.61317             2.30078             0.02289 
Fedfunds L(4)            -0.14852             0.12249            -1.21246             0.22739 
Inflat L(5)            -0.15941             0.08566            -1.86101             0.06486 
Unempl L(5)            -0.74153             0.59641            -1.24333             0.21584 
Fedfunds L(5)             0.34789             0.11648             2.98663             0.00333 
Inflat L(6)             0.09898             0.07580             1.30579             0.19378 
Unempl L(6)             0.01450             0.33055             0.04387             0.96507 
Fedfunds L(6)            -0.38014             0.08677            -4.38099             0.00002 
=====================================================================================================

The reported reduced-form results include:

  • The date range identified in the dataframe, data_shortrun.
  • The model estimated, based on the selected optimal number of lags, in this case SVAR(6).
  • Model diagnostics including R-squared (R-sq), the Durbin-Watson statistic (DW), Sum of the Squared Errors (SSE), and Root Mean Squared Errors (RMSE), by equation.
  • Parameter estimates, printed separately for each equation.

Customizing Our Model

The default model is a good start but suppose we want to make the following customizations:

  • Include two exogenous variables, trend and trendsq.
  • Exclude a constant.
  • Estimate a VAR(2) model.
  • Change the IRF/FEVD horizon from 20 to 40.
  • Change the IRF/FEVD confidence level from 95% to 68%

Implementing Model Customizations

Customization Tool Example
Adding exogenous variables. Adding a
"~"
and RHS variables to our formula string.
formula = "Inflat + Unempl + Fedfunds ~ date + trend + trendsq";
Specify identification method. Set our optional *ident* input to "oir". ident = "oir";
Exclude a constant. Set our optional *constant* input to 0. const = 0;
Estimate a VAR(2) model. Set the optional *lags* input. lags = 2;
Change the IRF/FEVD horizon. Update the irf.nsteps member of the
svarControl
structure.
sCtl.irf.nsteps = 40;
Change the IRF/FEVD confidence level. Update the irf.cl member of the
svarControl
structure.
sCtl.irf.cl = 0.68;

Putting everything together:

// Load library
new;
library tsmt;
/*
** Load data
*/
fname = "data_shortrun.dta";
data_shortrun = loadd(fname);
// Specify model formula string
// Three endogenous variable
// Two exogenous variables
formula = "Inflat + Unempl + Fedfunds ~ trend + trendsq";
// Identification method
ident = "oir";
// Estimate VAR(2)
lags = 2;
// Constant off
const = 0;
// Declare control structure
// and fill with defaults
struct svarControl sCtl;
sCtl = svarControlCreate();
// Update IRF/FEVD settings
sCtl.irf.nsteps = 40;
sCtl.irf.cl = 0.68;
/*
** Estimate VAR model
*/
struct svarOut sOut2;
sOut2 = svarFit(data_shortrun, formula, ident, const, lags, sCtl);
=====================================================================================================
Model:                      SVAR(2)                               Number of Eqs.:                   3
Time Span:              1960-01-01:                               Valid cases:                    162
2000-10-01                                                                   
Log Likelihood:            -413.627                               AIC:                         -3.185
SBC:                         -2.842
=====================================================================================================
Equation                             R-sq                  DW                 SSE                RMSE
Inflat                            0.83877             1.78639           159.81843             1.01872 
Unempl                            0.97835             5.82503             8.01756             0.22817 
Fedfunds                          0.91719             2.20585           135.51524             0.93807 
=====================================================================================================
Results for reduced form equation Inflat
=====================================================================================================
Coefficient            Estimate           Std. Err.             T-Ratio          Prob |>| t
-----------------------------------------------------------------------------------------------------
Inflat L(1)             0.65368             0.07951             8.22173             0.00000 
Unempl L(1)            -0.36875             0.34207            -1.07799             0.28272 
Fedfunds L(1)             0.19093             0.09600             1.98894             0.04848 
Inflat L(2)             0.17424             0.08324             2.09308             0.03798 
Unempl L(2)             0.30882             0.33838             0.91265             0.36285 
Fedfunds L(2)            -0.16561             0.09995            -1.65695             0.09956 
trend             0.03084             0.01278             2.41268             0.01701 
trendsq            -0.00019             0.00008            -2.55370             0.01163 
=====================================================================================================
Results for reduced form equation Unempl
=====================================================================================================
Coefficient            Estimate           Std. Err.             T-Ratio          Prob |>| t
-----------------------------------------------------------------------------------------------------
Inflat L(1)             0.04566             0.01781             2.56408             0.01130 
Unempl L(1)             1.48522             0.07662            19.38488             0.00000 
Fedfunds L(1)             0.01387             0.02150             0.64508             0.51983 
Inflat L(2)            -0.02556             0.01864            -1.37111             0.17234 
Unempl L(2)            -0.51248             0.07579            -6.76186             0.00000 
Fedfunds L(2)             0.02509             0.02239             1.12095             0.26406 
trend            -0.00587             0.00286            -2.05169             0.04189 
trendsq             0.00003             0.00002             1.99972             0.04729 
=====================================================================================================
Results for reduced form equation Fedfunds
=====================================================================================================
Coefficient            Estimate           Std. Err.             T-Ratio          Prob |>| t
-----------------------------------------------------------------------------------------------------
Inflat L(1)             0.00902             0.07321             0.12316             0.90214 
Unempl L(1)            -1.28526             0.31499            -4.08026             0.00007 
Fedfunds L(1)             0.93532             0.08840            10.58097             0.00000 
Inflat L(2)             0.19137             0.07665             2.49660             0.01359 
Unempl L(2)             1.25710             0.31159             4.03445             0.00009 
Fedfunds L(2)            -0.05845             0.09204            -0.63513             0.52629 
trend             0.00195             0.01177             0.16561             0.86868 
trendsq             0.00000             0.00007             0.03606             0.97128 
=====================================================================================================

Visualizing dynamics

The TSMT 4.0 library also includes a set of tools for quickly plotting dynamic shock responses after SVAR estimation. These functions take a filled svarOut structure and generate pre-formatted plots of IRFs, FEVDs, or HDs.

Function Description Example Usage
plotIRF Plots the Impulse Response Functions (IRFs) for the specified shock variables over time. IRFs illustrate how each variable responds to a shock in another variable. plotIRF(sOut, "Inflat");
plotFEVD Visualizes the Forecast Error Variance Decomposition (FEVD), which shows the contribution of each shock to the forecast error variance of each variable. plotFEVD(sOut);
plotHD Plots the Historical Decompositions (HD) plotHD(sOut);

Let's plot the IRFs, FEVDs, and HDs in response to a shock to Inflat from our customized model:

// Specify shock variable
shk_var = "Inflat";
// Plot IRFs
plotIRF(sout, shk_var);
// Plot FEVDs
plotFEVD(sout, shk_var);
// Plot HDs
plotHD(sout, shk_var);

This generates a grid plot of IRFs:

Impulse response functions in after shock to inflation using VAR(2) model.

An area plot of the FEVDs:

Forecast error variance decompositions in response to inflation shock.

And a bar plot of the HDs:

Example Two: Applying Long Run Restrictions

Long-run restrictions are often used in macroeconomic analysis to reflect theoretical assumptions about how certain shocks affect the economy over time. In this example, we follow the Blanchard-Quah (1989) approach to impose a long-run restriction that shocks to Unemployment do not affect GDP Growth in the long run.

Setting Up the Model

First we load our long-run dataset, data_longrun.dta, specify the model formula string and turn the constant off.

// Load the dataset
fname = "data_longrun.dta";
data_longrun = loadd(fname);
// Specify the model formula with two endogenous variables
formula = "GDPGrowth + Unemployment";
// Set lags to missing to use optimal lags
lags = miss();
// Constant off
const = 0;

To change the identification method, we use the optional ident input. There are three possible settings for identification, "oir", "bq", and "sign".

// Use BQ identification
ident = "bq";

Next we declare an instance of the svarControl structure and specify our irf settings.

// Declare the control structure
struct svarControl sCtl;
sCtl = svarControlCreate();
// Set irf Cl
sctl.irf.cl = 0.68;
// Expand horizon
sctl.irf.nsteps = 40;

Finally, we estimate our model and plot the dynamic responses.

// Estimate the SVAR model with long-run restrictions
struct svarOut sOut;
sOut = svarFit(data_longrun, formula, ident, const, lags, sCtl);
// Specify shock variable
shk_var = "GDPGrowth";
// Plot IRFs
plotIRF(sOut, shk_var);
// Plot FEVDs
plotFEVD(sOut, shk_var);
// Plot HDs
plotHD(sOut, shk_var);

This generates a grid plot of IRFs:

Impulse response functions after long-run restrictions.

An area plot of the FEVDs:

Forecast error vactor decompositions with long-run restrictions.

And a bar plot of the HDs:

Historic decompositions using long-run restrictions.

Conclusion

The svarFit procedure, introduced in TSMT 4.0, makes it much easier to estimate and analyze SVAR models in GAUSS. In this post, we walked through how to apply both short-run and long-run restrictions to understand the structural dynamics between variables.

With just a few lines of code, you can estimate the model, specify identification restrictions, and visualize the results. This flexibility allows you to tailor your analysis to different economic theories without getting bogged down in complex setups.

You can find the code and data for today's blog here.

Further Reading

  1. Introduction to the Fundamentals of Time Series Data and Analysis
  2. Introduction to the Fundamentals of Vector Autoregressive Models
  3. The Intuition Behind Impulse Response Functions and Forecast Error Variance Decomposition
  4. Introduction to Granger Causality
  5. Understanding and Solving the Structural Vector Autoregressive Identification Problem
  6. The Structural VAR Model at Work: Analyzing Monetary Policy

Leave a Reply