On 17/01/2024 12:34, Dhanasekaran Kuppusamy wrote:
Dear Gretl community*,
* I have two datasets A and B.
Both A and B have different variables but with common variable i.e. ID.
I want to merge these two data sets using ID as the common variable as
given below : data set C. Thanking you in advanceI would be thankful for
providing the solution. Note: A : Household data and B members data.
Dhanasekaran K
Generally speaking, what you need is the "join" command.: assuming your
two example dataset are in gdt format (but csv would work just as well),
you can add the data from A to B via
<hansl>
open dataset_b.gdt
join dataset_a.gdt x1 x2 x3 --ikey=ID
</hansl>
Reformatting the data as you dataset C is less easy, since you can't
assume that each household has the same number of members. The following
example shows what happens if you set the maximum number of family
members to 3:
<hansl>
open dataset_a.gdt
maxn = 3
loop i = 1 .. maxn
loop foreach j x4 x5
sname = sprintf("$j_%d", i)
join dataset_b.gdt @sname --data=$j --ikey=ID --aggr="seq:$i"
endloop
endloop
</hansl>
Having said all this, I'd recommend reading the Guide chapter titled
"Joining data sources".
-------------------------------------------------------
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
-------------------------------------------------------