Seasonal Adjustment

After reading excel file(of raw data) on matlab, I did makes some transformation on the data.
And in working directory, I get file “data_sample” of 61*44.

data_sample.mat (19.8 KB)
(I saved the file for question)

And “names_to_include” is 1*44 cell which include column name in the working directory.

Now for some columns of the matrix, I want to do seasonal adjustment so I write the code as following.

% Define list of variables to be seasonally adjusted
    'gov_lt','ppiN2','ppiT2', 'ppiM','ppi_A','ppi_E','ppiWX_cmo', 'ppiWN_cmo',...

% Define the X-13ARIMA-SEATS specification
spec1 = makespec('AUTO','PICK','X11','NO OUTLIERS');

% Copy the original data set to a new data set for seasonal adjustment

% Iterate through the variables to be seasonally adjusted
for j = 1:length(variables_to_sa)
    % Find the position of the variable in the data set
    pos_j = find(strcmpi(names_to_include, variables_to_sa{j}));
    % Extract the variable from the data set
    var_j = data_sample(:, pos_j);
    % Convert the variable to a dseries object
    var_j_ds = dseries(var_j,'1986Q1', variables_to_sa{j});
    % Perform the seasonal adjustment using X-13ARIMA-SEATS
    aux_j_sa = x13(var_j_ds, spec1);
    % Extract the seasonally adjusted series
    var_j_sa = aux_j_sa.e2;
    % Replace the original series in the data set with the seasonally adjusted series
    data_sample_sa(:, pos_j) = var_j_sa;

But I don’t know why but it keep giving me error message “The ‘dseries’ class is used as one of the default class definitions, property values, or attribute values within the class definition. This is not allowed.”

I’ll really appreciate for your help.

Thanks in advance

Where does the makespec-function come from?

I found the function on the X-13 Toolbox for Seasonal Filtering.

% MAKESPEC produces x13 specification structures. It makes the use of
% x13spec easier by providing quick access to meaningful specification
% combinations.
% Usage:
% spec = makespec(shortcut, [shortcut2, …])
% spec = makespec([shortcut], [section, key, value], …)
% spec = makespec([shortcut], [section, key, value], [spec1], …)
% Available shortcuts are:
% ‘DIAGNOSTIC’ produce ACF and spectra of the data; this is useful to
% determine if the data is seasonal at all
% ‘ACF’ subset of ‘DIAGNOSTIC’ without spectra (for quarterly
% data); saves (partial) auto-correlation functions
% ‘SPECTRUM’ save some spectra
% ‘STOCK’ Data is a stock variable. (This is relevant for the types of
% calendar dummies.)
% ‘FLOW’ Data is a flow variable.
% ‘AUTO’ let program select additive vs multiplicative filtering
% ‘MULTIPLICATIVE’ force multiplicative filtering
% ‘ADDITIVE’ force additive filtering
% ‘ESTIMATE’ estimate ARIMA, even if no seasonal adjustment is
% computed…"

In this case, the 'AUTO' argument indicates that the method should automatically determine the best ARIMA model for the time series, 'PICK' specifies that the method should determine the frequency of the data, 'X11' indicates that X-11 should be used to perform the seasonal adjustment, and 'NO OUTLIERS' specifies that no outlier detection should be performed.

And this is what I was trying to do with the code

  1. Finds the position of the current variable in names_to_include using the find function and the strcmpi function. The strcmpi function is used to perform case-insensitive comparison of strings.
  2. Extracts the data for the current variable from data_sample.
  3. Calls the x13 function to perform seasonal adjustment on the data using the specification spec1. The results are stored in a structure aux_j_sa.
  4. Extracts the seasonal adjusted data from aux_j_sa and stores it in var_j_sa.
  5. Updates the data in data_sample_sa with the seasonal adjusted

And the data is from 1986Q1 ~ 2016Q3 and second column is the date column

Did you try using x13 based on the description in the Dynare manual? My hunch is that Dynare’s dseries is incompatible with the Matlab package.