'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')
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | doncharles005 |
