MATRIX ARRANGEMENT PROBLEM MATLAB
Mostrar comentarios más antiguos
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 comentarios
Jan
el 14 de Jun. de 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."?
Saptorshee Chakraborty
el 14 de Jun. de 2022
Respuestas (1)
Cris LaPierre
el 14 de Jun. de 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 comentarios
Saptorshee Chakraborty
el 14 de Jun. de 2022
Cris LaPierre
el 15 de Jun. de 2022
You will need to provide more details then.
Saptorshee Chakraborty
el 15 de Jun. de 2022
Cris LaPierre
el 15 de Jun. de 2022
Editada: Cris LaPierre
el 15 de Jun. de 2022
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
el 15 de Jun. de 2022
Saptorshee Chakraborty
el 15 de Jun. de 2022
Cris LaPierre
el 15 de Jun. de 2022
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
el 15 de Jun. de 2022
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
el 16 de Jun. de 2022
Cris LaPierre
el 16 de Jun. de 2022
Editada: Cris LaPierre
el 16 de Jun. de 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
el 16 de Jun. de 2022
Categorías
Más información sobre Introduction to Installation and Licensing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!