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   Neil Shephard <[email protected]>
To   [email protected]
Subject   Re: st: merging datasets
Date   Wed, 18 Aug 2010 15:23:47 +0000

2010/8/18 Χρυσούλα Γιαννικοπούλου <[email protected]>:
> Hello Statalist,
>
> I am facing with a problem in merging 2 different datasets. I let you
> know that I use Stata 11.
>
> Both of the datasets have 13  variables each.
>
> I would like to merge them according to the variable "bvdep_id_mother" .
>
> For example, data look like:
>
> Dataset A
> bvdep_id                bvdep_id_mother     company_name
>          country              Year      ........
>
> ESA58527060        ESA08685471        TREFILERIAS QUIJANO SA        ES
>                   1998
>
> ESB08674384        ESA08685471        BARNA CONSHIPPING S.L.       ES
>                  2000
>
> ESB61477196       ESA08685471         BARNA  SA
>         ES                  2005
>
> ESA58527060        ESA08685471        TREFILERIAS QUIJANO SA        ES
>                  2003
> .
> .
> .
> For this dataset the bvdep_id_mother is the same for all observations.
>
> Dataset B
> bvdep_id(targetbvdepidnumber)
> bvdep_id_mother(acquirorbvdepidnumber)   dealvalue
>  country ........
>
> EE10366713                                           ESA08685471
>                                   31818.2                         ES
>
>
> NO936796702                                            1851.9
>                NO
> US78-689-8726
> NO964052131                                         IT28965
>                                        15584.89
> IT
> .
> .
> .
>
> Here, bvdep_id_mother is named acquirorbvdepidnumber and differs
> accross obsarvations.
>
>
> I tried this:
>
> **************************************************************************************
>
> set mem 500m
>
> use "B.dta"
>
> rename  acquirorbvdepidnumber bvdep_id_mother
>
> sort bvdep_id_mother
>
> save  "B.dta"
>
> clear
>
> set mem 500m
>
> use "A.dta"
>
> sort bvdep_id_mother
>
> merge 1:m bvdep_id using "B.dta"
>
> *********************************************************************************
>
> Finally, I have the error message:
> *************
> variable bvdep_id does not uniquely identify observations in the master data
> r(459);
>
> *************
>
>
> I have the same problem even if I give the command merge m:1 or even
> if I use as master dataset the "b.dta"
>
>
> Could you help me please? What do I do in a wrong way?
>

You're trying to merge on bvdep_id and not the bvdep_id_mother that
you stated you wanted to merge on. Also, as you state there are
multiple observations based on bvdep_id_mother in A.dta and that the
variable is unique in B then you would want to do an 'm:1' merge.

Neil


-- 
"One should as a rule, respect public opinion in so far as is
necessary to avoid starvation and to keep out of prison, but anything
that goes beyond this is voluntary submission to an unnecessary
tyranny, and is likely to interfere with happiness in all kinds of
ways..." - Bertrand Russell

Email - [email protected]
Website - http://slack.ser.man.ac.uk/
Photos - http://www.flickr.com/photos/slackline/

*
*   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