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: RE: merging - unique observations


From   Andreas Dimopoulos <[email protected]>
To   <[email protected]>
Subject   Re: st: RE: merging - unique observations
Date   Sun, 06 Apr 2014 22:54:24 +0100

Thanks a lot. It seems to be correct with the method you suggested!

Regards,
A


On Sun, 6 Apr 2014 15:23:35 +0900, "Joseph Coveney" <[email protected]>
wrote:
> Make sure that you get the m:1 or 1:m in the proper order.  If not, then
> you'll get the error you mentioned.  See below.
> 
> Joseph Coveney
> 
> . clear *
> 
> . set more off
> 
> . set linesize 79
> 
> . 
> . input str244(reporter partner) int period str2 trade
> 
> 
>>
>>
>>         reporter                                                       

>>
>>
>>
>>                         partner    period      trade
>   1. can usa 2000 k1
>   2. can usa 2002 k2
>   3. end
> 
> . 
> . tempfile tmpfil0
> 
> . quietly save `tmpfil0'
> 
> . 
> . drop _all
> 
> . 
> . input str244(reporter partner) str2 distance
> 
> 
>>
>>
>>         reporter                                                       

>>
>>
>>
>>                         partner   distance
>   1. can usa x1
>   2. can arg x2
>   3. end
> 
> . 
> . *
> . * Accidentally got it backwards (gives error message)
> . *
> . capture noisily merge m:1 reporter partner using `tmpfil0'
> variables reporter partner do not uniquely identify observations in the
> using
>     data
> 
> . 
> . *
> . * Got it right, here
> . *
> . merge 1:m reporter partner using `tmpfil0', ///
>>     keep(matched) noreport nogenerate
> 
> . 
> . sort reporter partner period
> 
> . list, noobs sepby(reporter partner)
> 
>   +------------------------------------------------+
>   | reporter   partner   distance   period   trade |
>   |------------------------------------------------|
>   |      can       usa         x1     2000      k1 |
>   |      can       usa         x1     2002      k2 |
>   +------------------------------------------------+
> 
> . 
> . exit
> 
> end of do-file
> 
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Andreas
> Dimopoulos
> Sent: Sunday, April 6, 2014 13:34
> To: [email protected]
> Subject: Re: st: RE: merging - unique observations
> 
> My first dataset is like:
> 
> reporter partner period trade
> can       usa      2000   k1
> can       usa      2002   k2
> 
> and my second dataset is like:
> 
> reporter partner  distance
> can        usa     x1
> can        arg     x2
> 
> A difference between the datasets is that the second one has every pair
of
> countries in the sample while the first one not. For example, the pair
> CAN-ARG does not exist in the first one. Hope that helps?
> 
> Regards,
> A
> 
> 
> On Sun, 6 Apr 2014 00:35:33 +0000, Joe Canner <[email protected]> wrote:
>> Andrew,
>> 
>> It is difficult to say for sure what the problem is without more
details
>> about your data, what command(s) you ran, and the exact error message
> you
>> received.
>> 
>> However, it appears that at least one of the problems is that your
first
>> data set has multiple observations per country-pair (one for each year)
>> while the second data set has only one observation per country-pair. 
If
>> this is the case, try a many-to-one merge:
>> . merge m:1 countrypair using distancedata
>>  
>> I can also imagine other problems that might arise from the use of
>> country-pairs as the merging key, but we would have to know more about
> your
>> data in order to diagnose them.
>> 
>> Regards,
>> Joe Canner
>> Johns Hopkins University School of Medicine
>> 
>> ________________________________________
>> From: [email protected]
>> [[email protected]] on behalf of Andreas Dimopoulos
>> [[email protected]]
>> Sent: Saturday, April 05, 2014 5:47 PM
>> To: [email protected]
>> Subject: st: merging - unique observations
>> 
>> Good evening,
>> 
>> I have two datasets where the first one contains pairs of countries and
>> their in between trade for different years and another dataset which
has
>> the pair of countries and their in between distance etc (which don't
> change
>> over time). I tried to merge those two datasets based on the things I
> have
>> read but stata tells me that the observations cannot be uniquely
>> identified.
>> 
>> Any piece of advise?
>> 
>> Regards,
>> Andrew
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/faqs/resources/statalist-faq/
>> *   http://www.ats.ucla.edu/stat/stata/
>> 
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/faqs/resources/statalist-faq/
>> *   http://www.ats.ucla.edu/stat/stata/
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
> 
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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