Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: Trying to create a unique match


From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   st: Re: Trying to create a unique match
Date   Tue, 10 Jul 2007 12:36:36 -0400

.....
It looks like you want to do 1:1 nearest neighbor matching between the datasets without replacement. Perhaps -nnmatch- will help, but I'm not sure if it can do without replacement. -nearmrg- was not written with that intent.


Michael Blasnik

----- Original Message ----- From: "Hugh Colaco" <[email protected]>
To: "statalist" <[email protected]>
Sent: Tuesday, July 10, 2007 12:07 PM
Subject: st: Trying to create a unique match



Hi,

Please see the example and the problem I am facing below. Any help in
getting around this issue will be much appreciated.

Thanks in advance,

Hugh


USING FILE

sysuse auto, clear
sort weight
drop if weight[_n]==weight[_n-1]
gen id_2 =_n
save auto1, replace


MASTER FILE


id_1 weight
1 1825
2 1825
3 2010
4 2017
5 2023


input id_1 weight
sort weight
nearmrg using auto1, nearvar(weight) genmatch(weight_merged) update
save master, replace


If you run this, you will find that the first two observations of the
MASTER file are matched with the same observation (i.e. weight=1830
from the USING file) as can be expected. Similarly, the last three
observations of the MASTER file are matched with the same observation
(i.e. weight=2020  from the USING file). This occurs because -nearmrg-
picks the closest match.

However, I require that all the five matches be unique (i.e. they
should not be repeated). In other words, for a given "weight" in the
MASTER file, I need the closest match from the USING file. The next
observation "weight" from the MASTER file (even if it equals the
previous "weight") must be directed to the next closest observation
from the USING file. The end result is that I should have five unique
matches.
*
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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