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: Nearmrg deleting unmerged observations
From
Eric Booth <[email protected]>
To
[email protected]
Subject
Re: st: Nearmrg deleting unmerged observations
Date
Fri, 12 Jul 2013 10:03:18 -0500
<>
Hi Lara:
You can merge your dataset back to the "master" dataset and keep all the observations - here's an example that expands on the example in the help file:
*******************
**1: create 'using' data**
webuse autoexpense.dta, clear
rename make make2
sa "using.dta", replace
**2: merge to auto.dta by price**
sysuse auto.dta, clear
sa "master.dta", replace
nearmrg using "using.dta", upper nearvar(price) genmatch(usingmatch) limit(50)
list make* price usingmatch _m if inrange(_m, 3, 5)
drop _merge
**merge back to the master to get all the unmatched obs:
merge 1:1 make using "master.dta"
*******************
- Eric
On Jul 12, 2013, at 9:50 AM, Lara Loewenstein <[email protected]> wrote:
> I'm using nearmrg to merge two datasets by street address. But I want
> an approximate merge for the street number while an exact merge for
> the street name. I also have multiple cities in the master dataset,
> while only one city in the using dataset, so I want to merge in the
> using dataset for that one city while keeping the unmerged
> observations in the master dataset. My code looks like this:
>
> nearmrg street city using "UsingData", nearvar(stnum) limit(10)
> genmatch(using_stnum) update
>
> The problem is, that when I do this, nearmrg automatically deletes all
> the unmerged data, so all i'm left with is a subset of the city in the
> using dataset that managed to merge with the master data.
>
> How do I get nearmrg to keep all the observations, both merged and
> unmerged? I tried adding the keep option from the standard merge
> command, adding keep(1/5) since I'm updating a variable as well, but
> that caused nearmrg to delete all the observations and left me with an
> empty dataset.
>
> Many thanks.
>
> Lara Loewenstein
> *
> * 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/