Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: merging data sets using an interaction of demographics

From   Seb Buechte <[email protected]>
To   [email protected]
Subject   Re: st: merging data sets using an interaction of demographics
Date   Wed, 2 Mar 2005 10:17:33 +0100

You might want to try the following:

make sure the four variables "age race income state" uniquely identify
any observation (be aware of missings!). You should check on both
files. Then, what was suggested before, you take the joinby command.
Like this

use master.dta
joinby age race income state using "dataset_on_disk.dta",
umatched(master) _merge(_merge)

tab _merge

If you still read more observation in your merged dataset than in the
master dataset that is most likely due to some lacking uniqueness of
your "key", e.g. if you had in you master.dta two obs with all four
variables'  values "age race income state" set to missing and in your
dataset_on_disk.dta you had 4 obs with these variables taking missing
values you would had ended up in six more observations than expected (
2 obs x 4 obs = 8 new obs instead of originally two). So, one needs to
be careful.

On Mon, 28 Feb 2005 23:11:33 -0500, Richard Williams
<[email protected]> wrote:
> At 09:40 PM 2/28/2005 -0500, you wrote:
> >I have two data sets A and B. I have a variable in B that I can't observe
> >in A however each data set contains common demographics from which I can
> >create a interaction term in each data set (ie age,race,income,state) I
> >can assign unique values to each interaction and merge the two data sets
> >on this interaction therefore getting my varible of interest in set A. My
> >question is that I can't get the number of observations in my merged data
> >set to equal the number of observations in the master data set "A"(ie
> >merge 3 contains more obervations than merge 1)
> You might also check out the FAQ on "Why does my merge produce a dataset
> with too many observations?"  As it suggests, use the -isid- command to
> make sure your ids really are unique.
> -------------------------------------------
> Richard Williams, Notre Dame Dept of Sociology
> OFFICE: (574)631-6668, (574)631-6463
> FAX:    (574)288-4373
> HOME:   (574)289-5227
> EMAIL:  [email protected]
> WWW (personal):
> WWW (department):
> *
> *   For searches and help try:
> *
> *
> *

- Seb F Buechte
- Stay tuned!
*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index