X13PATH environmental variable not found

Problem

You are building a Time Series Arima model using statsmodels.tsa.x13 and get an error message.

x12a and x13as not found on path. Give the path, put them on PATH, or set the X12PATH or X13PATH environmental variable.

Cause

You do not have the required X13 binaries in your path.

Solution

Download the X13 binaries and declare the location as the X13PATH in your notebook.

  1. Download x13asall_V1.1_B39.tar.gz fromhttps://www.census.gov/srd/www/x13as/x13down_unix.html.

  2. Untar the file to a folder.

  3. In the notebook click File.

  4. Click Upload Data.

  5. Upload the folder you created from x13asall_V1.1_B39.tar.gz.

  6. Verify the files exist on the cluster.

    %fs ls dbfs:/FileStore/shared_uploads/<path-to-uploaded-X13-folder>/
    
  7. Define X13PATH as the path to the uploaded X13 folder.

    X13PATH = "/dbfs/FileStore/shared_uploads/<path-to-uploaded-X13-folder>/"
    
  8. You can now successfully build the model

Example code

import statsmodels.api  as sm
from statsmodels.tsa.x13 import x13_arima_select_order, _find_x12
from statsmodels.tsa.x13 import x13_arima_analysis

import pandas as pd
from pandas import Timestamp
import scipy
import numpy as np
import matplotlib.pyplot as plt
import os

s = pd.Series(
    {Timestamp('2013-03-01 00:00:00'): 838.2,
     Timestamp('2013-04-01 00:00:00'): 865.17,
     Timestamp('2013-05-01 00:00:00'): 763.0,
     Timestamp('2013-06-01 00:00:00'): 802.99,
     Timestamp('2013-07-01 00:00:00'): 875.56,
     Timestamp('2013-08-01 00:00:00'): 754.4,
     Timestamp('2013-09-01 00:00:00'): 617.48,
     Timestamp('2013-10-01 00:00:00'): 994.75,
     Timestamp('2013-11-01 00:00:00'): 860.86,
     Timestamp('2013-12-01 00:00:00'): 786.66,
     Timestamp('2014-01-01 00:00:00'): 908.48,
     Timestamp('2014-02-01 00:00:00'): 980.88,
     Timestamp('2014-03-01 00:00:00'): 1453.73,
     Timestamp('2014-04-01 00:00:00'): 1473.33,
     Timestamp('2014-05-01 00:00:00'): 1480.44,
     Timestamp('2014-06-01 00:00:00'): 1433.91,
     Timestamp('2014-07-01 00:00:00'): 1386.58,
     Timestamp('2014-08-01 00:00:00'): 1437.35,
     Timestamp('2014-09-01 00:00:00'): 1207.07,
     Timestamp('2014-10-01 00:00:00'): 973.3,
     Timestamp('2014-11-01 00:00:00'): 962.18,
     Timestamp('2014-12-01 00:00:00'): 717.69,
     Timestamp('2015-01-01 00:00:00'): 873.06,
     Timestamp('2015-02-01 00:00:00'): 881.65,
     Timestamp('2015-03-01 00:00:00'): 1252.92,
     Timestamp('2015-04-01 00:00:00'): 866.94,
     Timestamp('2015-05-01 00:00:00'): 1498.05,
     Timestamp('2015-06-01 00:00:00'): 1282.31,
     Timestamp('2015-07-01 00:00:00'): 1411.33,
     Timestamp('2015-08-01 00:00:00'): 1379.05,
     Timestamp('2015-09-01 00:00:00'): 1334.52,
     Timestamp('2015-10-01 00:00:00'): 1231.86,
     Timestamp('2015-11-01 00:00:00'): 1088.14,
     Timestamp('2015-12-01 00:00:00'): 967.35,
     Timestamp('2016-01-01 00:00:00'): 1266.37,
     Timestamp('2016-02-01 00:00:00'): 1278.79,
     Timestamp('2016-03-01 00:00:00'): 1497.8,
     Timestamp('2016-04-01 00:00:00'): 1352.27},
    name='Cost')

res = sm.tsa.x13_arima_analysis(s,x12path=X13PATH)
res.plot()
plt.show()

Example result

Plot of results