doncharles005
doncharles005

Reputation: 53

How to Run an impulse response on a VAR in Python

I am seeking to run a impulse response on a VAR is Python This is my code below

#import the libraries

import numpy as np
import pandas as pd
import statsmodels.api as sm
import matplotlib.pyplot as plt

#import the data

df=pd.read_excel(r"C:\Users\Action\Downloads\SMG.xlsx",index_col='Date',parse_dates=True)

#name the variables

ser=df['Services']
man=df['Manufacturing']
GDP=df['GDP growth']

#run the model

mod = sm.tsa.VARMAX(df[['GDP growth', 'Manufacturing', 'Services']], order=(2,0), trend='n')
res = mod.fit(maxiter=1000, disp=False)
print(res.summary())

I can generate 1 impulse response function with the code below

ax = res.impulse_responses(10, orthogonalized=True, impulse=[1, 0]).plot(figsize=(13,3))
ax.set(xlabel='t', title='Responses to a shock to `GDP growth`');

but how to I run the impulse response for all the variables I am trying the following code but it is not helping

irf = res.irf(10)
irf.plot(impulse ='10yT')

Upvotes: 0

Views: 3522

Answers (2)

Saeed
Saeed

Reputation: 2089

If you want all variables to be treated as impulse variables, just leave the impulse argument of the irf function blank and do not pass any variable names to it. The same is true for the response argument. So, basically, if you leave both the impulse and response arguments blank, it is going to test all possible impulse-response relationships between all of the variables. This is a good idea actually. From that, you can see which relationships are interesting and then focus on them further.

Upvotes: 0

doncharles005
doncharles005

Reputation: 53

A VAR is an econometric model. It is one that is a system of equations. Each endogenous variable becomes a dependent variable in its one equation and becomes a function of itself and lags of the other endogenous variables. An impulse response is used to analyze a VAR. What an Imuplse Response does is when the VAR system is shocked, and shock goes to variable first, it shows how each of the other endogenous variables will respond to the shock. It shows which variables will increase or decrease, in which lags, and by which magnitude. A VAR with 2 variables should have 4 impulse response functions. Each one shows a different scenario about how the variables will respond to the shock. However, my code is only generating 1 scenario of the impulse response. I want to know how to amend the code so that it can generate all 4 scenarios of the impulse response.

Upvotes: 1

Related Questions