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)?
Thanks again for the assistance.
Mike
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.
>
> Michael Blasnik
> [email protected]
>
> ----- Original Message -----
> From: "Michael Horowitz" <[email protected]>
> To: <[email protected]>
> Sent: Sunday, August 31, 2003 4:08 PM
> Subject: st: Question about merging two datasets
>
>
> > I have a problem that I was wondering if someone out there could help me
> > with. I have two datasets. Lets call them dataset A and dataset B.
> > Dataset A contains contains two variables, <city> and <income>. Dataset
> B
> > also contains two variables, <city> and <income>. Dataset A is much
> > larger than Dataset B and the data in Dataset B is more accurate than the
> > data in Dataset A. Specifically, the income levels for the cities in
> > dataset A are sometimes incorrect and I need to replace them with the
> > correct income levels from dataset B.
> >
> > So I need to merge datasets A and B, matching for when the name of the
> > city is the same and inserting the income score from dataset B into
> > dataset A when the two disagree.
> >
> > I've tried the various merge commands but I cannot seem to get the
> command
> > right to make it work.
> >
> > Could someone please assist? I would be quite appreciative.
> >
> > Sincerely,
> > Michael Horowitz
> >
> >
> ****************************************************************************
> *******************************
> >
> > Michael Horowitz
> > 78 Kirkland Street, #1
> > Cambridge, MA 02138
> >
> >
> > *
> > * 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/
> >
>
>
> *
> * 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/
>
*
* 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/