DATA ARRANGEMENT FROM PANEL FORMAT
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Saptorshee Chakraborty
el 17 de Mzo. de 2020
Comentada: Saptorshee Chakraborty
el 21 de Mzo. de 2020
Hello,
I have a data of 5 variables (x1, x2, x3, x4, x5) for 24 countries of 28 years. (N = 24, T = 28, d = 5) in panel format. I want to arrange X = (x_{11}, ..., x_{1T}, ..., x_{N1}, ..., x_{NT})'.
How do I proceed.
0 comentarios
Respuesta aceptada
Raunak Gupta
el 20 de Mzo. de 2020
Hi,
I assume you have 28 tables corresponding to 28 years with 5 variables for all 24 countries based on my understanding of panel format data. So, each table contains all 24 countries and 5 variables for it. You can create a matrix first for each variable X1, X2, X3, X4, X5. Then can read each of the 28 tables and assign the columns to corresponding variable column. Then you can flatten each variable matrix in row major form to get the output. You may find below code useful.
% Let say tablei is the table having 24 rows and 5 column
% corresponding to x1,x2,x3,x4,x5
% Lets say you have tables stored as .csv file and all the names of .csv
% files are stored in vector tableName.
N = 24;
T = 28;
d = 5;
X1mat = zeros(N,T);
X2mat = zeros(N,T);
X3mat = zeros(N,T);
X4mat = zeros(N,T);
X5mat = zeros(N,T);
for i=1:size(tableName,1) % For the number of years
tablei = readtable(tabelName(i));
X1mat(:,i) = tablei.x1;
X2mat(:,i) = tablei.x2;
X3mat(:,i) = tablei.x3;
X4mat(:,i) = tablei.x4;
X5mat(:,i) = tablei.x5;
end
% Creating vector by Reshaping in row major form
X1 = reshape(X1mat.',1,[]);
X2 = reshape(X2mat.',1,[]);
X3 = reshape(X3mat.',1,[]);
X4 = reshape(X4mat.',1,[]);
X5 = reshape(X5mat.',1,[]);
2 comentarios
Raunak Gupta
el 21 de Mzo. de 2020
Hi,
Based on the data you have provided lets say XOriginal is the matrix of dimension (NTxd) and for arranging this matrix, for arranging XOriginal in the given format try the below code.
dummyX = reshape(XOriginal,[28,24,5]);
Xfinal = permute(dummyX,[2,1,3]);
Also for arranging Y you can just reshape the vector in [28,24] then can take transpose of that array.
dummyY = reshape(YOriginal,[28,24]);
Yfinal = dummyY.';
Hope this provide the solution you want.
Más respuestas (1)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!