Little but Loud #1

Formatting panel data for Stata software.

January 02, 2023 · 5 mins read
PanelData_for_Stata
% % Panel Data format for Stata

In this short explanation, let's describe a formula that eliminates a significant loss of time in panel data analysis. In performing panel data analysis in Stata package program, the researcher should prepare the data set in panel format. Consider, id and t show individual and time dimensions of panel data. the individual units are in the id column and the time values are in the t column.

Here is an example: Consider we have 3 countries 2011-2020 time series data (It is a micropanel, huh!). Thus we have T=10. Then only you have to do run stataentrance.m file:

clear; close; clc;
N=3; T=10;

output=stataenterance(N,T)

This format is easily reached with the stataentrance.m function below:

function output = stataenterance(N,T)
%   generating id and t coulumns in stata
%   helping stata data enterance
    time=(1:T)';
    t=repmat(time,N,1);
        idc=cell(N,1);
    for j=1:N
        idc{j} = repmat(j,T,1);
    end
    id=cell2mat(idc);
    output=[id t];
end
output =

     1     1
     1     2
     1     3
     1     4
     1     5
     1     6
     1     7
     1     8
     1     9
     1    10
     2     1
     2     2
     2     3
     2     4
     2     5
     2     6
     2     7
     2     8
     2     9
     2    10
     3     1
     3     2
     3     3
     3     4
     3     5
     3     6
     3     7
     3     8
     3     9
     3    10