Thank you very much for sharing this practical example. I never knew it was this easy to extract data from dbnomics.

On Fri, 27 Sep 2019 at 22:47, Allin Cottrell <cottrell@wfu.edu> wrote:
On Fri, 27 Sep 2019, Artur Tarassow wrote:

> Am 27.09.19 um 13:08 schrieb ΑΝΔΡΕΑΣ ΖΕΡΒΑΣ:
> >
> > Just a quick question: suppose that one has several files with time series,
> > e.g. several files with macro data, each file for a country (or maybe one
> > file with time series from several countries). Is there a way to create from
> > hansl a panel dataset, without copying (stacking) the data into a
> > spreadsheet?
>
> Hi Andreas,
> almost everyhting can be done with gretl ;-)
>
> You will need the join command for this type of work. See ch. 7 in
> the manual.

"join" is not the only tool that could be used for this job but I
think Artur is right: it should work well. Here's a little example, in
the form of two scripts (which could be combined). The first reads
some series from dbnomics -- annual population and employment for
Germany, France and Italy -- and writes a time-series dataset; the
second creates a panel dataset and fills it using "join", drawing from
the time-series data.

<hansl>
# script 1: create time-series dataset
set verbose off
include dbnomics.gfn

nulldata 38
setobs 1 1980

provider = "IMF"
database = "WEO"
bundle spec = null
spec["weo-country"] = defarray("FRA", "DEU", "ITA")
spec["weo-subject"] = defarray("LP", "LE")
bs = dbnomics_get_multiple(provider, database, 20, 0, spec)

list X = null
loop i = 1..nelem(bs) --quiet
    sn = fixname(bs[i].series_code, 1)
    series tmp = NA
    dbnomics_bundle_get_data(bs[i], &tmp)
    # add series to list
    X += genseries(sn, tmp)
endloop

# save the per-country time-series data
store tmp.gdt X
</hansl>

<hansl>
# script 2: convert to panel
# 38 years, 3 countries
NT = 38 * 3
nulldata NT
setobs 38 1:01 --stacked-time-series
series country = $unit
series Employment
series Population
strings cnames = defarray("DEU", "FRA", "ITA")
# set the sample to each country in turn
loop i = 1..3 --quiet
  smpl country == i --restrict --replace
  ename = sprintf("%s_LE", cnames[i])
  pname = sprintf("%s_LP", cnames[i])
  join tmp.gdt Employment --data="@ename"
  join tmp.gdt Population --data="@pname"
endloop
smpl full
setinfo Employment --description="Employment - Persons"
setinfo Population --description="Population - Persons"
store dbn_panel.gdt
</hansl>

Allin Cottrell_______________________________________________
Gretl-users mailing list -- gretl-users@gretlml.univpm.it
To unsubscribe send an email to gretl-users-leave@gretlml.univpm.it
Website: https://gretlml.univpm.it/postorius/lists/gretl-users.gretlml.univpm.it/


--

Yusuf Abdulwahab Hassan.
Department of Economics and Development Studies.
Federal University of Kashere,Gombe.
+234 8036830166.
yabdulwahab@fukashere.edu.ng