MATRIX ARRANGEMENT PROBLEM MATLAB

1 次查看(过去 30 天)
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
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."?

请先登录,再进行评论。

回答(1 个)

Cris LaPierre
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 个评论
Cris LaPierre
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
Thank you very much indeed, I appreciate your help.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by