I use the following test data and code to test the exog
parameters of sm.tsa.x13_arima_analysis
from statsmodels
, but an error occurs, how could I solve it? Thanks a lot.
import statsmodels.api as sm
import pandas as pd
import numpy as np
import os
datelist = pd.date_range(pd.to_datetime('2012-12-31'), periods=1500).tolist()
date_df = pd.DataFrame(datelist, columns=['dates'])
endog = pd.concat([date_df, pd.DataFrame(np.random.randint(0, 100, size=(1500, 1)), columns=list('a'))], axis=1)
exog = pd.concat([date_df, pd.DataFrame(np.random.randint(0, 100, size=(1500, 1)), columns=list('b'))], axis=1)
endog.index = endog.dates
endog = endog.drop(['dates'], axis=1)
exog.index = exog.dates
exog = exog.drop(['dates'], axis=1)
endog = endog.resample('M').mean()
exog = exog.resample('M').mean()
X13PATH = r'D:\EconomicDataSeasonalAdjustTool\X13\x13as'
# the link to download X13as model: https://www.census.gov/data/software/x13as.html
os.chdir(X13PATH)
os.environ['X13PATH'] = X13PATH
print(os.environ['X13PATH'])
res = sm.tsa.x13_arima_analysis(endog=endog, exog=exog, x12path=X13PATH, print_stdout=True)
print(res.seasadj)
print(res.plot)
Out:
Traceback (most recent call last):
File "C:\Python\Python310\lib\site-packages\IPython\core\interactiveshell.py", line 3553, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-12-21406d809098>", line 12, in <cell line: 12>
res = sm.tsa.x13_arima_analysis(endog=endog, exog=exog, x12path=X13PATH, print_stdout=True)
File "C:\Users\LSTM\AppData\Roaming\Python\Python310\site-packages\pandas\util\_decorators.py", line 210, in wrapper
return func(*args, **kwargs)
File "C:\Users\LSTM\AppData\Local\Programs\Python\Python310\lib\site-packages\statsmodels\tsa\x13.py", line 518, in x13_arima_analysis
_check_errors(errors)
File "C:\Users\LSTM\AppData\Local\Programs\Python\Python310\lib\site-packages\statsmodels\tsa\x13.py", line 201, in _check_errors
raise X13Error(errors)
statsmodels.tools.sm_exceptions.X13Error: ERROR: forecasts end date, 2018.Feb, must end on or before
user-defined regression variables end date, 2017.Feb.
Finally, the code below works after by adding
forecast_years=0
:Out: