Clear Filters
Clear Filters

What's worng with this code

2 views (last 30 days)
형현
형현 on 1 Feb 2024
Commented: Dyuman Joshi on 1 Feb 2024
% Verify that the Economics Toolbox is installed
if ~license('test', 'Econometrics_Toolbox')
error ('Economics Toolbox is required');
end
% Set Excel file path and sheet name
file_path = 'Korean currency combination.xlsx';
sheet_name = 'Sheet1';
% Importing data from an Excel file
data = xlsread(file_path, sheet_name);
Error using xlsread
Unable to open file 'Korean currency combination.xlsx'.
File '/users/mss.system.GOd8xe/Korean currency combination.xlsx' not found.
% Setting Variables
E_Price = data(:, 1);
Volume = data(:, 3);
Bond = data(:, 4);
Exchange = data(:, 5);
KOSPI = data(:, 6);
Construction = data(:, 7);
CC2 = data(:, 8);
Vacancy = data(:, 9);
Rent = data(:, 10);
KOFR = data(:, 11);
% Dividend yield (dependent variable) converted from the outside to the next level
DivideYield = data (:, 2); use the second column of Excel file as dividend yield as an example of %
% Configuring an Independent Variable Matrix
X = [E_Price, Volume, Bond, Exchange, KOSPI, Construction, CC2, Vacancy, Rent, KOFR];
% Setting Dependent Variables
Y = DividendYield;
% Create VAR Model
var_model = var(size(X, 2), 1); create a VAR model to match the number of % variables
% Data Settings
data_matrix = [Y, X];
% Estimating VAR Model
var_model = estimate(var_model, data_matrix);
% Output VAR model information
disp(var_model);
Error:
Index at location 2 exceeds array boundaries, index must not exceed 10.
Data seems to be a function and a variable at the same time. If this is not intended, use 'clear data' to remove the variable 'data' from the workspace.
Korean currency combination.xlsx = 한화 합본.xlsx
What's wrong with this codes
  2 Comments
Walter Roberson
Walter Roberson on 1 Feb 2024
Edited: Walter Roberson on 1 Feb 2024
% Verify that the Economics Toolbox is installed
if ~license('test', 'Econometrics_Toolbox')
error ('Economics Toolbox is required');
end
% Set Excel file path and sheet name
file_path = '한화 합본.xlsx';
sheet_name = 'Sheet1';
% Importing data from an Excel file
data = xlsread(file_path, sheet_name);
% Setting Variables
E_Price = data(:, 1);
Volume = data(:, 3);
Bond = data(:, 4);
Exchange = data(:, 5);
KOSPI = data(:, 6);
Construction = data(:, 7);
CC2 = data(:, 8);
Vacancy = data(:, 9);
Rent = data(:, 10);
KOFR = data(:, 11);
% Dividend yield (dependent variable) converted from the outside to the next level
DividendYield = data (:, 2); %use the second column of Excel file as dividend yield as an example of %
% Configuring an Independent Variable Matrix
X = [E_Price, Volume, Bond, Exchange, KOSPI, Construction, CC2, Vacancy, Rent, KOFR];
% Setting Dependent Variables
Y = DividendYield;
% Create VAR Model
var_model = var(size(X, 2), 1); %create a VAR model to match the number of % variables
% Data Settings
data_matrix = [Y, X];
% Estimating VAR Model
var_model = estimate(var_model, data_matrix);
Incorrect number or types of inputs or outputs for function estimate.
% Output VAR model information
disp(var_model);
estimate() requires that a model be passed. To create a VAR model you would use something similar to LagOp
Dyuman Joshi
Dyuman Joshi on 1 Feb 2024
In addition to what Walter has mentioned,
> Use the more robust readtable (or readmatrix) instead of the depracated xlsread().
>The variable names don't match -
DivideYield = data(:, 2);
Y = DividendYield;
> The first column is the date-time data, not E_Price. There is a mismatch for other variables as well. And there is no data column named KOFR in the excel file

Sign in to comment.

Answers (0)

Categories

Find more on Multivariate Models in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!