On Wed, 28 Sep 2022, Cottrell, Allin wrote:
As Sven has said, this case is more awkward than the (more common)
case for
which gretl's stack() function is designed.
You may or may not like this, but I'd say that the best way of handling the
data you describe is to convert the dataset to a matrix, use gretl's matrix
manipulation facilities to rearrange the data in stacked time-series form,
then convert back to a dataset.
Here's hansl code that does the job, taking as input a toy version of the
setup you describe (attached as loddick.csv). You'll have to adjust one or
two things for your real case (names of the variables, and the dimensions T
and N). You can of course delete the verbose feedback on the script's
progress via "printf".
It's a matter of taste, I know, but some people may find a little
variation of Allin's script more readable: the loop
<hansl>
NT = N * T
matrix X1 = zeros(NT, nvars)
r0 = 0
loop i=1..N
printf "original row %d\n", i
col = 1
loop j=1..nvars
printf " variable %d\n", j
loop t=1..T
printf " observation %d\n", t
X1[r0+t,j] = X0[i,col]
col++
endloop
endloop
r0 += T
endloop
</hansl>
could be replaced with more compact (although probably not as transparent)
syntax as follows:
<hansl>
matrix X1 = {}
# loop over the rows of the original dataset and reshape them
# as needed
loop i=1..N
printf "original row %d\n", i
X1 = X1 | mshape(X0[i,], T, nvars)
endloop
</hansl>
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------