Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: merging datasets


From   Maarten Buis <[email protected]>
To   [email protected]
Subject   Re: st: merging datasets
Date   Tue, 4 Sep 2012 09:32:26 +0200

On Sat, Sep 1, 2012 at 4:33 PM, Khalida Akhtar Choudhury wrote:
> I need to merge household head in my dataset. In one of my datasets, I
> have a variable which describes the household head, however, in my
> other datasets, I do not. The id that is used across all datasets is
> not unique, so that individuals from the same household have the same
> id.
>
> I don't know how to merge for household head across all the datasets.


*------------------ begin example --------------------
// create some example data
clear all
tempfile hh hh_head

// create individual level data
// hh 1 is a "standard" family
// hh 2 is a young couple without kids
// hh 3 is a widow
input hh_id person_id urban nkids married age  female
      1     1         1     2     1       41   0
      1     2         1     2     1       40   1
      1     3         1     2     1       10   1
      1     4         1     2     1       12   1
      2     1         0     0     0       25   0
      2     2         0     0     0       26   1
      3     1         0     0     2       81   1
end
save `hh'
drop _all

// create household head data
input hh_id person_id education
      1     1         17
      2     1         15
      3     1          4
end
save `hh_head'

// -merge- if we want to use the information from
// the household head to all members of the family:
use `hh'
merge m:1 hh_id using `hh_head'
list, sepby(hh_id)	

// -merge- if we want to use the information from
// the household head only for the household head:
drop _all
use `hh'
merge 1:1 hh_id person_id using `hh_head'
list, sepby(hh_id)
*------------------- end example ---------------------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )

Hope this helps,
Maarten

---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany

http://www.maartenbuis.nl
---------------------------------
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index