MATRIX ARRANGEMENT PROBLEM MATLAB
古いコメントを表示
Hello,
I am working with panel structural breaks, where , and X1, X2, X3 (d=3).
Now I have three breaks, B=3, while the author uses the code with B=1 and GB, GA (for me it will be GI, GII, GIII, GIV)
I am stuck at T_frac, Y_frac, X_frac somehow the index becomes more than 3.
I am permission to use the code of the author, any help will be appreciated.
Xvec = [x1, x2, x3];
Yvec = y;
N=114;
TT=48;
xlag = x(:,1:TT-1,:);
ylag = y(:,2:TT);
T = TT-1;
Xmat = xlag;
ymat = ylag;
p = size(Xmat,3);
S = 30;
SSR = zeros(1,(T-2));
SSR(1) = inf;
ymatfd = diff(ymat,1,2);
Xmatfd = diff(Xmat,1,2);
for j = 1:B
for bk = 2:(T-2)
regime = [0,bk,T-1]; % Get the bounds of potential subperiods
for aa = 1:(j+1)
T_frac = length((regime(aa)+1):(regime(aa+1)));
y_frac = reshape(ymatfd(:,(regime(aa)+1):(regime(aa+1)))',N*T_frac,1);
for l = 1:p
X_frac(:,l) = reshape(Xmatfd(:,(regime(aa)+1):(regime(aa+1)),l)',N*T_frac,1);
end
time_frac = repmat(1:T_frac,1,N)';
code_frac = kron((1:N)',ones(T_frac,1));
idxdata_frac = dataset(code_frac, time_frac, y_frac, X_frac);
idxdata_frac.Properties.VarNames = {'N' 'T' 'y' 'X'};
if aa == 1
[~,~,ssr,] = est_group(idxdata_frac,GB);
elseif aa == 2
[~,~,ssr,] = est_group(idxdata_frac,GA);
end
SSR(bk) = SSR(bk) + ssr;
clear X_frac y_frac idxdata_frac time_frac code_frac
end
end
[resQ,k] = min(SSR); % Compare SSR to get a breakdate
end
2 件のコメント
Jan
2022 年 6 月 14 日
"Now I have three breaks, B=3, while the author uses the code with B=1 and GB, GA (for me it will be GI, GII, GIII, GIV)" - remember, that the readers do not know, what you are talking off. Who is the autheor? What us GB and GA, GI, GII, GIII and GIV?
What does this mean: "I am stuck at T_frac, Y_frac, X_frac somehow the index becomes more than 3."?
Saptorshee Chakraborty
2022 年 6 月 14 日
回答 (1 件)
Cris LaPierre
2022 年 6 月 14 日
Not that your loop counter is j, but your indexing uses j+1, and then again use loop counter aa, but index using aa+1. Therefore, when B=3, j+1=4 and aa+1=5.
for j = 1:B
...
for aa = 1:(j+1)
T_frac = length((regime(aa)+1):(regime(aa+1)));
% ^^^^
end
end
12 件のコメント
Saptorshee Chakraborty
2022 年 6 月 14 日
Cris LaPierre
2022 年 6 月 15 日
You will need to provide more details then.
Saptorshee Chakraborty
2022 年 6 月 15 日
Cris LaPierre
2022 年 6 月 15 日
編集済み: Cris LaPierre
2022 年 6 月 15 日
Please attach the file data.mat to your post using the paperclip icon.
Also, what do you mean by "change GB and GA to GI=3, GII=3, GIII=2, GIV=3"? As best I can tell, you have no variables GI, GII, GIII, GIV.
Saptorshee Chakraborty
2022 年 6 月 15 日
Saptorshee Chakraborty
2022 年 6 月 15 日
Cris LaPierre
2022 年 6 月 15 日
Please share all your variables so that we can run your code. You can save them all to a single mat file. Currently we need
- X1
- X2
- X3
- y
Saptorshee Chakraborty
2022 年 6 月 15 日
Here, regime is a 1x3 vector. When j=1, the max value of aa is 2, so regime(2) and regime(3) both work. However, when j is 2, the max value of aa is 3. While regime(3) works, regime(4) does not.
B = 3;
T = 47;
for j = 1:B
j
for bk = 2:(T-2)
regime = [0,bk,T-1]; % Get the bounds of potential subperiods
for aa = 1:(j+1) ;
T_frac = length((regime(aa)+1):(regime(aa+1)));
end
end
end
Saptorshee Chakraborty
2022 年 6 月 16 日
Cris LaPierre
2022 年 6 月 16 日
編集済み: Cris LaPierre
2022 年 6 月 16 日
I didn't mention a fix. I just pointed out the code that was causing the problem.
The fix is to make regime longer. It needs to be a 1x(B+2) vector to not error. Again, it is currently 1x3, so when B=1, the code works. When B=3, it needs to be 1x5.
I don't know what values to add, though. That is something where you would need to apply your knowledge in this space to corectly adjust the code.
Saptorshee Chakraborty
2022 年 6 月 16 日
カテゴリ
ヘルプ センター および File Exchange で Introduction to Installation and Licensing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!