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

st: Re: ST: populating a variable based on a second data set


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   st: Re: ST: populating a variable based on a second data set
Date   Tue, 24 Jun 2003 20:59:08 -0500

----- Original Message ----- 
From: "Webb.Bayard" <[email protected]>
To: <[email protected]>
Sent: Tuesday, June 24, 2003 5:45 PM
Subject: st: ST: populating a variable based on a second data set


> Hi, I'm a new Stata user with a merge problem.
>
> I have one data set (call it A) with a variable that needs to be defined
in
> terms of the observations in a second data set (B). I don't know if this
can
> be done with a single command or if it needs to be programmed.
> Basically, B is a lookup table. I need to lookup the contents of an A var
in
> B, and return the value of a different B var corresponding to the same
data
> point.
>
> Thanks in advance for any suggestions.
>
> Bayard
>
>
> Example
> A =
>    type
> 1 human
> 2 cat
> 3 human
> 4 dog
> 5 rat
> 6 cat
>
>
> B =
>    type tail
> 1 human 0
> 2 cat 1
> 3 dog 1
> 4 rat 1
>
>
> AFTER OPERATION
> A =
>    type tail
> 1 human 0
> 2 cat 1
> 3 human 0
> 4 dog 1
> 5 rat 1
> 6 cat 1

-joinby- might be what you need.


. use "C:\DATA\foo1.dta", clear

. l

     +-------+
     |  type |
     |-------|
  1. | human |
  2. |   cat |
  3. | human |
  4. |   dog |
  5. |   rat |
     |-------|
  6. |   cat |
     +-------+

. joinby type using c:\data\foo2.dta

. l

     +--------------+
     |  type   tail |
     |--------------|
  1. |   cat      1 |
  2. |   cat      1 |
  3. |   dog      1 |
  4. | human      0 |
  5. | human      0 |
     |--------------|
  6. |   rat      1 |
     +--------------+

Hope this helps,
Scott



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