Jorge Alonso
Jorge Alonso

Reputation: 123

How do I make a year index that statsmodels vector Autoregression can recognize?

I am struggling to make that statsmodels.tsa.api.VAR recognize my index as an annual frequency

I have a data frame, that is a panel, with a country (panel dimension) and a year variable (time dimension)

df = df.set_index([‘country’, ‘year’])

Then I iteratively estimate the stuff I need to estimate for each country with this code


for cont in countries:
    exog = df[exogVars].xs(cont).dropna()
    
    # We estimate first a SVAR with GDP p.c.
    endog = df[endogVars].xs(cont).dropna()

    svar_st = VAR(endog, exog)
    svar_f = svar_st.fit(maxlags = 4, ic = 'aic', trend = 'nc')

And I get the work done, but not without a warning message that indicates:

ValueWarning: An unsupported index was provided and will be ignored when e.g. forecasting

Despite I may not be interested in forecasting, I am bugged about why this is happening. Can anybody help?

Thanks

Upvotes: 2

Views: 254

Answers (1)

cfulton
cfulton

Reputation: 3195

The year index must be a Pandas PeriodIndex with annual frequency. You can probably make it work with something like the following:

df['year'] = pd.PeriodIndex(df['year'], freq='A')
df = df.set_index([‘country’, ‘year’])

# ...

Upvotes: 1

Related Questions