i use Nakajima‘s code to do the 3 variable TVP-VAR model。Now I want to do a 4-variable TVP-VAR model but i have no idea how to revise the original code.The code is as follows and i put the entile code in the attachment.Thanks for your help!
clear all; close all;
load tvpvar_ex; % data (.mat)
asvar = {'index'; 'v'; 'm2'; }; % variable names nlag = 2; % lags
setvar('data', my, asvar, nlag); % set data
setvar('fastimp', 1); % fast computing of response
mcmc(10000); % MCMC
drawimp([4 8 12], 1); % draw impulse reponse(1) % : 4-,8-,12-period ahead
drawimp([30 60 90], 0); % draw impulse response(2) % : response at t=30,60,90

댓글 수: 2

Savas Gayaker
Savas Gayaker 2019년 8월 11일
Thank you for your answer. can this code be extended to five or more variables
Luyao Yang
Luyao Yang 2022년 12월 25일
Hi, do you know how to draw a 3D-irf in Matlab?it should be tvp-var model

댓글을 달려면 로그인하십시오.

답변 (3개)

Savas Gayaker
Savas Gayaker 2019년 6월 25일

0 개 추천

I am looking for the same thing. Since 2016 no one has any answer I guess. Did you find anything ? İf you found, could you share it with me ?

댓글 수: 1

Ameer Fahmi
Ameer Fahmi 2019년 11월 2일
편집: Ameer Fahmi 2019년 11월 2일
The code can work with four variables, you just neet to introduce your fourth variable in the 'asvar' function as follows
asvar = {'y1'; 'y2'; 'y3'; 'y4' }; % variable names
And that's it

댓글을 달려면 로그인하십시오.

zhen lu
zhen lu 2019년 8월 11일

0 개 추천

if you want do a 4-variable TVP-VAR model, firstly you should put the data of the fourth series data into tvpvar_ex file, and add the name of it into "asvar = {'index'; 'v'; 'm2'; }, like {'index'; 'v'; 'm2','X'; } . Here X means the name of variable you want to add. And maybe the format of code is wrong, you may take the following code.
clear all;
close all;
load tvpvar_ex; % data (.mat)
asvar = {'index'; 'v'; 'm0'; }; % variable names
nlag = 2; % lags
setvar('data', my, asvar, nlag); % set data
setvar('fastimp', 1); % fast computing of response
mcmc(10000); % MCMC
drawimp([4 8 12], 1); % draw impulse reponse(1)
% : 4-,8-,12-period ahead
drawimp([30 60 90], 0); % draw impulse response(2)
% : response at t=30,60,90

댓글 수: 1

yuanxin
yuanxin 2022년 2월 9일
请问后面的代码该怎么改?它的图还是三个变量的图

댓글을 달려면 로그인하십시오.

song song
song song 2019년 10월 27일

0 개 추천

How to draw the 3D impulse response figure ?

댓글 수: 3

Ameer Fahmi
Ameer Fahmi 2019년 11월 2일
The impulse response functions at each point are exported to excel file named 'tvpvar_imp' in the directory, but it is vertically arranged, like the horizons of impusle response functions are in columns, this is the data of impulse response functions exported to the excel file
The first column is the time, and second column is the horizons, the rest of the columns are the response of variables to shocks in other variables
Untitled.png
What you need to do is to put the responses of the variable of interest in rows instead of columns, this can be easily done by using the filtering options in excel
Let's say I have the variables (OP, IR,R,IPI) and I want to draw a 3D plot of the response of IR to OP shocks, you can see that impulse variable and the response variables are already sprcified in the the first two rows, what you need to do is the following
First, in excel put the cursor on the first cell, then go to DATA and select filter, in the second column select the horizon 0, this will filter all the 0 horizons at each time point, copy the values corresponding to IR in the response row and past it in a new sheet, then select the horizon 1, copy it and past it next to the values of 0 horizons, filter the horizon 2 values and put it next to the values of 1 horizons in the new sheet, do the same with rest of the horizons, in the end you'll get a matrix in which the horizons of each impulse response function are stacked in rows, import it to MATLAB as matrix, then you can plot it selecting the options of 3D plots, you can then customize the Y axis according to the dates of your time series.
song song
song song 2019년 11월 2일
Thank you for your answer.
But my excel filt named "tvpvar_imp.xls" is different with yours. I have three variables, so My form has nine columns. Just like this.Is our code different?
QQ截图20191102211504.png
Ameer Fahmi
Ameer Fahmi 2019년 11월 3일
편집: Ameer Fahmi 2019년 11월 3일
This is weird, the horizons, the impulse variable and the response variable must be there, otherwise the program will not be able to draw the figure of cumulative impulse responses at different horizons as well as the responses at different time points. The graphs are based on these outputs
I think there's a problem with your results, the values of the response are zero which indicate for singular matrix, meaning that the variables have no impact on each other. Are you using randomly selected variables? or maybe there is a mistake in your settings of the variables and lags
You should also look to the other reported graphs, like the figure of MCMC draws, stochastic volatility figure and simultaeous relations. The MCMC draws must be uncorrelated, follow a stable line and normally distributed. If it doesn't then your estimations are not correct. In addition, you should notice fluctuations in the figure of the stochastic volatility, if it is constant and unchanged then there is no time variations in the parameters of your variables.
I could help you more if you post pictures for the rest of the figures.

댓글을 달려면 로그인하십시오.

카테고리

질문:

f x
2016년 7월 8일

댓글:

2022년 12월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by