On Wed, 8 Jun 2022, Cottrell, Allin wrote:
On Tue, Jun 7, 2022 at 12:29 PM Ioannis Venetis
<ioannisvenetis(a)gmail.com> wrote:
>
> I attach two gdt panel data files (is what I managed to do, TIME is a time index, GEO
lists 38 countries/regions, and two variables CP00, CP01),
>
> example1.gdt goes from 2016:01-2018:12 and
> example2.gdt goes from 2019:01-2022:04
>
> (A) is there an "easy" way to "join" the two gdt files into one
time-larger file? running from 2016:01:-2022:04?
> (B) how can i "easily" transform the panel dataset into a time-series set
with 38 CP00 series, say EU_CP00, EA_CP00,... and 38 CP01 series, EU_CP01, EA_CP01,...?
On question (B) here's a slight refinement of Sven's suggestion:
<hansl>
open example1.gdt
set skip_missing off
matrix X = mshape({CP00}, $pd)
S = strvals(GEO)
loop i=1..nelem(S)
S[i] = "CP00_" ~ S[i]
endloop
cnameset(X, S)
T = rows(X)
nulldata T --preserve
setobs 12 2019:01
list CP00 = mat2list(X)
print CP00 -o
</hansl>
In the spirit of "it's nice to have more ways to do something", here's
an
alternative (probably inferior) solution.
<hansl>
clear
open example1.gdt
S = strvals(GEO)
T = $pd
nulldata T --preserve
setobs 12 2019:01
loop i=1..nelem(S)
c = S[i]
flt = sprintf("GEO==\\\"%s\\\"", c)
fn = fixname(c)
join example1.gdt @fn --data="CP00" --filter="@flt"
endloop
</hansl>
That said, it may be nice to write a function package providing a function
like this, with a signature like
function scalar unstack(list X, string fname)
which would save the time-series data into "fname.gdt" (I imagine it would
return an error code).
-------------------------------------------------------
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
-------------------------------------------------------