Statalist


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

st: Trying to create a unique match


From   "Hugh Colaco" <hmjc66@gmail.com>
To   statalist <statalist@hsphsun2.harvard.edu>
Subject   st: Trying to create a unique match
Date   Tue, 10 Jul 2007 12:07:47 -0400

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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index