Prepare Time Series Data for Econometric Modeler App
These examples show how to prepare time series data at the MATLAB® command line for use in the Econometric Modeler app.
You can import only one variable into Econometric Modeler. The variable can exist in the MATLAB Workspace or a MAT-file.
A row in a MATLAB timetable contains simultaneously sampled observations. When you import a timetable, the app plots associated times on the x axis of time series plots and enables you to overlay recession bands on the plots. Therefore, these examples show how to create timetables for univariate and multivariate time series data. For other supported data types and variable orientation, see Prepare Data for Econometric Modeler App.
Prepare Table of Multivariate Data for Import
This example shows how to create a MATLAB timetable from synchronized data stored in a MATLAB table. The data set contains annual Canadian inflation and interest rates from 1954 through 1994.
At the command line, clear the Workspace, then load the
Data_Canada.mat
data set. Display all variables in
the workspace.
clear all load Data_Canada whos
Name Size Bytes Class Attributes Data 41x5 1640 double DataTable 41x5 8107 table DataTimeTable 41x5 3827 timetable Description 34x55 3740 char dates 41x1 328 double series 1x5 878 cell
Data
, DataTable
, and
DataTimeTable
contain the time series, and
dates
contains the sampling years as a numeric
vector. The row names of DataTable
are the sampling
years. For more details about the data set, enter
Description
at the command line.
Time series plots in Econometric Modeler label the
x-axis with sampling times when they are attached to
the data. Although you can import DataTimeTable
to use
this feature, consider preparing DataTable
as a
timetable.
Clear the row names of DataTable
.
DataTable.Properties.RowNames = {};
Convert the sampling years to a datetime
vector.
Specify the years, and assume that measurements were taken at the end of
December. Specify that the time format is the sampling year.
dates = datetime(dates,12,31,'Format','yyyy');
Convert the table DataTable
to a timetable by
associating the rows with the sampling times in
dates
.
DTT = table2timetable(DataTable,'RowTimes',dates);
DTT
is a timetable containing the five time series and
a variable named Time
representing the time base.
DTT
is prepared for importing into Econometric
Modeler.
If your time series are not synchronized (that is, do not share a common
time base), then you must synchronize them before you import them into the
app. For more details, see synchronize
and Combine Timetables and Synchronize Their Data.
Prepare Numeric Vector for Import
This example shows how to create a timetable from a univariate time series stored as a numeric column vector. The data set contains the quarterly US gross domestic product (GDP) prices from 1947 through 2005.
At the command line, clear the workspace, then load the
Data_GDP.mat
data set. Display all variables in the
workspace.
clear all load Data_GDP whos
Name Size Bytes Class Attributes Data 234x1 1872 double DataTable 234x1 32337 table DataTimeTable 234x1 4727 timetable Description 22x59 2596 char dates 234x1 1872 double
Data
contains the time series, and
dates
contains the sampling times as serial date
numbers. For more details about the data set, enter
Description
at the command line.
Convert the sampling times to a datetime
vector. By
default, MATLAB stores the hours, minutes, and seconds when converting from
serial date numbers. Remove these clock times from the data.
dates = datetime(dates,'ConvertFrom','datenum','Format','ddMMMyyyy',... 'Locale','en_US');
Create a timetable containing the data, and associate each row with the
corresponding sampling time in dates
. Name the variable
GDP
.
DTT = timetable(Data,'RowTimes',dates,'VariableNames',{'GDP'});
DTT
is a timetable, and is prepared for importing into
Econometric Modeler.