This is a follow-up to
http://lists.wfu.edu/pipermail/gretl-users/2015-March/010772.html
It strikes me that the issue raised -- namely, how to wrangle
"difficult" data into gretl panel format -- may be of interest to
others so I've thought about it a bit more.
First a disclaimer: the method outlined below cannot be applied
mechanically to the ICPSR data mentioned by Christian. One would
have to go through the codebook very carefully to see which
variables actually "line up" across the waves of the study.
All the same, here's a toy example that might be helpful as a
template. It's in the form of two scripts: the first creates an
artificial dataset that mimics the general structure of the ICPSR
"Children of the Immigrants" data, and the second shows how the data
can be turned into a gretl panel.
1. Make the artificial data:
<hansl>
# let's suppose we have data on 50 individuals
# over 3 "waves", with the respective per-wave
# observations recorded as distinct variables
# (columns), here 10 columns per wave
nulldata 50
# unique ID for the individuals
series casenum = 10000 + index
# create a bunch of artificial data (30 series)
loop i=1..30 --quiet
series v$i = index * i
if i > 20
v$i += 20
elif i > 10
v$i += 10
endif
endloop
# write to CSV file
store rawdata.csv
</hansl>
2. Process the data into a panel
<hansl>
open rawdata.csv --quiet
# the number of longitudinal waves
scalar nwaves = 3
# the total number of panel observations
scalar NT = $nobs * nwaves
# create lists of series per wave
list L1 = v1..v10
list L2 = v11..v20
list L3 = v21..v30
# make a vector repeating the case numbers
matrix C = mshape({casenum}, NT, 1)
# matrix consisting of three vertically stacked
# components, each of which holds a wave number
# followed by the observations for that wave
matrix X = ({1}~{L1}) | ({2}~{L2}) | ({3}~{L3})
# note that X has an extra column for the wave
scalar nx = cols(X) - 1
# create empty dataset for panel
nulldata NT --preserve
# trash the automatic "index" variable
delete index
# add the casenum series from vector
series casenum = C
# add the wave number series from the first
# column of matrix X
series wave = X[,1]
# add the actual data
loop i=1..nx --quiet
series pan$i = X[,i+1]
endloop
# let's take a look...
print --byobs
# now turn into gretl panel format
setobs casenum wave --panel-vars
# and take a look again...
print --byobs
</hansl>
Allin Cottrell