Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Re: Question about merging two datasets


From   Ernest Berkhout <[email protected]>
To   [email protected], [email protected]
Subject   Re: st: Re: Question about merging two datasets
Date   Mon, 01 Sep 2003 10:56:14 +0200

At 00:03 1-9-2003, [email protected] wrote:
What if I have other variables besides city and income in dataset A and dataset
B (and they are different variables in each dataset) but I only want to merge
in the matching incomes from dataset B to replace the incorrect ones in dataset
A (i.e. I want to leave alone the rest of the variables in dataset A)?

Quoting Michael Blasnik <[email protected]>:

> This appears to be a most basic merge.
>
> assuming that dataset A is already sorted by city, then:
>
> use B
> sort city
> merge city using A
>
>
> These commands will result in a combined dataset where the value of income
> from B takes precedence.
Please take a look at the magnificent mmerge.ado by Jeroen Weesie, it should handle your problem quite easily (type -ssc inst mmerge- ).
The trick is to specify that values of the master dataset A should be overwritten if there is disagreement with corresponding values in using dataset B. That is:

use A
mmerge city using B, ukeep(income) replace update



Ernest Berkhout
SEO Amsterdam Economics
University of Amsterdam

Room 3.08
Roetersstraat 29
1018 WB Amsterdam
The Netherlands

tel.:+ 31 20 525 1657
fax:+ 31 20 525 1686
http://www.seo.nl
===========================
A statistician: someone who insists
on being certain about uncertainty
===========================

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