MATRIX ARRANGEMENT PROBLEM MATLAB

2 views (last 30 days)
Saptorshee Chakraborty
Saptorshee Chakraborty on 14 Jun 2022
Edited: Cris LaPierre on 16 Jun 2022
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 Comments
Jan
Jan on 14 Jun 2022
"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."?

Sign in to comment.

Answers (1)

Cris LaPierre
Cris LaPierre on 14 Jun 2022
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 Comments
Cris LaPierre
Cris LaPierre on 16 Jun 2022
Edited: Cris LaPierre on 16 Jun 2022
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
Saptorshee Chakraborty on 16 Jun 2022
Thank you very much indeed, I appreciate your help.

Sign in to comment.

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!