What's worng with this code

1 回表示 (過去 30 日間)
형현
형현 2024 年 2 月 1 日
コメント済み: Dyuman Joshi 2024 年 2 月 1 日
% 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 件のコメント
Walter Roberson
Walter Roberson 2024 年 2 月 1 日
編集済み: Walter Roberson 2024 年 2 月 1 日
% 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 2024 年 2 月 1 日
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

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by