How To Organize Panel Data i

Occasional Contributor
Posts: 13

How To Organize Panel Data i

Hi All,

I am confused about how to arrange my data to run a probit model.

I have data on 484 farms over 132 months for four variables. I am aware the data needs to be in stacked form such that farms have a column, months have a column, and variables are in their respective columns, rather than a column for each month as is currently the case.

Currently, I have each variable in its own matrix/spreadsheet. Here is the Quantity Matrix:

Month_1    Month_2 .... Month_j

Farm_1    Q_1_1       Q_1_2            Q_1_j

Farm_2    Q_2_1       Q_2_2            Q_2_j

.                  .

.

Farm_i    Q_i_1       Q_i_2                Q_i_j

I have matrices of equal dimensions for prices, costs, and exit decision. Column j represents the j'th month and row i represents the i'th farm in each matrix.

If anyone can give me some guidance about how to arrange this data, I would greatly appreciate it. Thanks!!

Posts: 1,270

Re: How To Organize Panel Data i

[ Edited ]

May be this is what you are looking for

data have;
input Farm \$ Month_1 \$ Month_2 \$ Month_3 \$;
datalines;
Farm_1 Q_1_1 Q_1_2 Q_1_3
Farm_2 Q_2_1 Q_2_2 Q_2_3
;

data want(keep=farm months values);
set have;
array m(*) m:;
do i=1 to dim(m);
Months=vname(m(i));
Values=m(i);
output;
end;
run;

PROC Star
Posts: 1,288

Re: How To Organize Panel Data i

Using PROC TRANSPOSE will get you most of the way there:

data Var1;

input Farm \$ Month_1 Month_2 Month_3;

cards;

Farm1 1 2 3

Farm2 4 5 6

Farm3 7 8 9

run;

proc sort data=Var1;

by Farm;

proc transpose data=Var1 out=TransposedVar1(rename=(col1=Var1));

by Farm;

run;

Discussion stats
• 2 replies
• 306 views
• 0 likes
• 3 in conversation