I hope you can help me with an issue I am having with the python time series code for SVAR from statsmodels.tsa.vector_ar.svar_model.
When I run the SVAR command below it appears that I am unable to include exogenous variables in the model. In the standard VAR code you are able to add exogenous variables to your model, and then run impulse responses.
The code for SVAR is as follows:
A = np.asarray([[1,0,0,0,0],['E',1,0,0,0], ['E','E',1,0,0], ['E','E','E',1,0],['E','E','E','E',1]])
B = np.asarray([['E',0,0,0,0],[0,'E',0,0,0], [0,0,'E',0,0], [0,0,0,'E',0],[0,0,0,0,'E']])
endogenous_vars = ["r","dyca", "infl", "dm","dex"]
exogenous_vars=["dpcm"]
model = SVAR(reg_data[endogenous_vars], svar_type='AB', A=A, B=B)
results = model.fit(maxlags=12, solver='bfgs')
irf=results.irf(periods=48)
irf.plot()
response=['dyca','dm','dex'] #<--- these are the first-differenced variables with a trend, so I use impulse accumulated effects to get the correct output graphs
# for reasons I am not sure, I can not get the three vars on the same graph so I run a loop to generate a graph for each one
for i in response:
irf.plot_cum_effects(impulse='r', response=i, plot_stderr=True, stderr_type='mc', repl=1500)
But every time I run this code, I get the same error:
irf.plot_cum_effects(impulse='r', response=i, plot_stderr=True, stderr_type='mc', repl=1500)
stderr = self.cum_errband_mc(orth=orth, repl=repl,
return model.irf_errband_mc(orth=orth, repl=repl,
ma_coll = self.irf_resim(
ma_coll[i, :, :, :] = fill_coll(sim)
ret = VAR(sim, exog=self.exog).fit(maxlags=k_ar, trend=self.trend)
SVARResults' object has no attribute 'exog'
self.exog is defined only in the source code:
_model_type = 'SVAR'
def __init__(self, endog, endog_lagged, params, sigma_u, lag_order,
A=None, B=None, A_mask=None, B_mask=None, model=None,
trend='c', names=None, dates=None):
self.model = model
self.endog = endog
self.endog_lagged = endog_lagged
self.dates = dates
self.n_totobs, self.neqs = self.endog.shape
self.nobs = self.n_totobs - lag_order
k_trend = util.get_trendorder(trend)
if k_trend > 0: # make this the polynomial trend order
trendorder = k_trend - 1
else:
trendorder = None
self.k_trend = k_trend
self.k_exog = k_trend # now (0.9) required by VARProcess
self.trendorder = trendorder
self.exog_names = util.make_lag_names(names, lag_order, k_trend)
self.params = params
self.sigma_u = sigma_u
# Each matrix needs to be transposed
reshaped = self.params[self.k_trend:]
reshaped = reshaped.reshape((lag_order, self.neqs, self.neqs))
# Need to transpose each coefficient matrix
intercept = self.params[0]
coefs = reshaped.swapaxes(1, 2).copy()
#SVAR components
#TODO: if you define these here, you do not also have to define
#them in SVAR process, but I left them for now -ss
self.A = A
self.B = B
self.A_mask = A_mask
self.B_mask = B_mask
super().__init__(coefs, intercept, sigma_u, A, B,
names=names)
The issue as I can see it, is that in the SVAR code line, I am unable to specify any exogenous variables.
Am I missing something really simple? Any and all help would be greatly appreciated.