DATA ARRANGEMENT FROM PANEL FORMAT
조회 수: 2 (최근 30일)
이전 댓글 표시
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
채택된 답변
Raunak Gupta
2020년 3월 20일
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
Raunak Gupta
2020년 3월 21일
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.
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!