文档介绍:Reshaping Panel Data Using Excel and Stata
Moonhawk Kim
Department of Political Science
Stanford University
June 27, 2003
Figure 1: Downloaded Panel Data
Figure 2: anized Panel Data
Many of us frequently find ourselves in situations of downloading panel data from having
to “reshape” data from Figure 1 to Figure 2. That is, many external databases (. World
1
Bank’s World Development Indicators) download panel data in a format, in which units and
data series go down the rows and time periods go across columns. This is not a helpful
format for either data analysis or for importing into your own database table. Accordingly,
you need to convert the format from Figure 1 to Figure 2. Before I learned this trick, I used
to copy and concatenate relevant columns, which took me hours!
This memo will walk you through an example of converting the format from “wide” to
“long” and then back to “wide.” Each worksheet in the panying Excel file (“Sample-
“) matches up with each of the steps below.
We are starting with the worksheet “Initial Download”. This is the same as Figure 1.
1. Stata requires the variables over which we perform the mand to be num-
bers rather than string. Thus, we start by assigning each unit—here countries—a
unique ID number:
(a) Create column for IDs (“unit id”). Insert “1” to the first observation of Sweden.
Then type and fil