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 theEconometric Modeler应用程序。
你可以只有一个变量导入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 thexaxis 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, seePrepare 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 theData_Canada.mat
data set. Display all variables in the workspace.
clearallloadData_Canadawhos
Name Size Bytes Class Attributes Data 41x5 1640 double DataTable 41x5 8379 table Description 34x55 3740 char dates 41x1 328 double series 1x5 918 cell
Data
andDataTable
contain the time series, anddates
contains the sampling years as a numeric vector. The row names ofDataTable
are the sampling years. For more details about the data set, enterDescription
at the command line.
Clear the row names ofDataTable
.
DataTable.Properties.RowNames = {};
Convert the sampling years to adatetime
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 tableDataTable
to a timetable by associating the rows with the sampling times indates
.
DataTable = table2timetable(DataTable,'RowTimes',dates);
DataTable
是一个timetable containing the five time series and a variable namedTime
representing the time base.DataTable
is prepared for importing intoEconometric 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, seesynchronize
and把时间表和同步数据.
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 theData_GDP.mat
data set. Display all variables in the workspace.
clearallloadData_GDPwhos
Name Size Bytes Class Attributes Data 234x1 1872 double Description 22x59 2596 char dates 234x1 1872 double
Data
contains the time series, anddates
contains the sampling times as serial date numbers. For more details about the data set, enterDescription
at the command line.
Convert the sampling times to adatetime
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 indates
. Name the variableGDP
.
DataTable = timetable(Data,'RowTimes',dates,'VariableNames',{'GDP'});
DataTable
是一个timetable, and is prepared for importing into Econometric Modeler.