Manually write code for a Vector Autoregression
이전 댓글 표시
I am trying to manually write the code to get VAR(1) coefficients without using the built-in function from the Econometrics toolbox. There are three variables in the "beta" matrix, and I created the first lags of each of these three. Then, I applied OLS to each equation separately using a for loop, and stored the estimates in a matrix A.
I am also trying to compute the variance-covariance matrix of residuals. So, I thought of collecting the residuals first but when I do that inside the for loop, I received an error message: "unable to perform assignment because brace indexing is not supported of variables of this type"
In general, I am not sure if this is an efficient way to code VAR and get coefficient estimates and variance. So, if you have any suggestions on how to improve the code, I'd be very grateful for your help.
% create lagged values of beta
lag1_beta = lagmatrix(beta,1);
% apply OLS to each equation separately
for i = 1:size(beta,2) % counts the # of columns in the beta matrix
for j =['level', 'slope', 'curv']
VAR_{j} = fitlm(lag1_beta, beta(:, i), 'Intercept', false);
a{i} = VAR_{j}.Coefficients.Estimate';
resid{j} = VAR_{j}.Residuals.Raw';
end
end
% stack the coefficients of the individual OLS estimates
A =[a1; a2; a3]
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


