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]

From |
Eric Booth <ebooth@ppri.tamu.edu> |

To |
"<statalist@hsphsun2.harvard.edu>" <statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: how to encode 2 var's? |

Date |
Tue, 1 Mar 2011 03:30:35 +0000 |

<> Similar to what Fernando already suggested, I like using making a lookup table to merge to each list of names. You mention that this cannot be done because of people being in "higher" or "lower" positions -- my guess is that this means that the names in the 2 variables appear in different observations (so they don't line up), even if this is the case, I still think merging in the list of names is a good solution. Here's an example of one way to accomplish this (you will need to install Nick Cox's -labmask- found via the command -findit labutil- ): **************! clear **create fake dataset** if _rc ssc install labmask, replace inp str15(name1) str15(name2) othervar "Tom Smith" "Ann Jones" 1 "John Tompkins" "Joe Summers" 2 "Ann Jones" "Ian Johnson" 43 "Joe Summers" "Tom Smith" 22 "B Jones" "Tom Smith" 99 end li **create look up tables** preserve stack name*, g(2) clear drop _stack duplicates drop g id1 = _n sa "lookup1.dta", replace li rename name1 name2 rename id1 id2 sa "lookup2.dta", replace li restore **merge data & encode variables** forval n = 1/2 { merge m:1 name`n' using "lookup`n'.dta" drop if _m!=3 drop _m **make sure labutil/labmask is installed labmask id`n', values(name`n') } l, nolab **************! -- If the fake data I provide do not represent the 2 variables you are working with, please provide more details/examples. - Eric __ Eric A. Booth Public Policy Research Institute Texas A&M University ebooth@ppri.tamu.edu On Feb 28, 2011, at 8:31 PM, Muyang Zhang wrote: > It may not work for me, for the two variables are for lower and higher > positions. Some people previously at the lower position appears at the > higher position later when other guys are at lower position. So > merging may not work as far as I am concerned. Thanks anyway. > > > On Mon, Feb 28, 2011 at 9:27 PM, Fernando Rios Avila <f.rios.a@gmail.com> wrote: >> my suggestion is: >> - if the name is written in the same way (exactly) in both variables, then >> just encode the first one, and merge the new code with the second one using >> the name as the id variable. >> perhaps that will help >> >> >> On Mon, Feb 28, 2011 at 9:13 PM, Fernando Rios Avila >> <ecofrax@langate.gsu.edu> wrote: >>> >>> >>> ---------- Forwarded message ---------- >>> From: Muyang Zhang <zmyfudan@gmail.com> >>> To: statalist@hsphsun2.harvard.edu >>> Date: Mon, 28 Feb 2011 21:11:13 -0500 >>> Subject: st: how to encode 2 var's? >>> I have two variables of people's name with several names appear in >>> both variables. How could I encode the two variables that returns the >>> same id for the same people in both variables? >>> >>> -- >>> Zhang Muyang >>> China Center for Economic Research >>> Peking University >>> Beijing, 100871 >>> China. >>> * >>> * For searches and help try: >>> * http://www.stata.com/help.cgi?search >>> * http://www.stata.com/support/statalist/faq >>> * http://www.ats.ucla.edu/stat/stata/ >>> Content-Type: text/plain; charset=US-ASCII >>> Content-Transfer-Encoding: quoted-printable >>> Content-Disposition: inline >>> >>> I have two variables of people's name with several names appear in >>> both variables. How could I encode the two variables that returns the >>> same id for the same people in both variables? >>> >>> --=20 >>> Zhang Muyang >>> China Center for Economic Research >>> Peking University >>> Beijing, 100871 >>> China. >>> * >>> * For searches and help try: >>> * http://www.stata.com/help.cgi?search >>> * http://www.stata.com/support/statalist/faq >>> * http://www.ats.ucla.edu/stat/stata/ >>> >>> >> >> > > > > -- > Zhang Muyang > China Center for Economic Research > Peking University > Beijing, 100871 > China. > > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/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/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**Re: st: how to encode 2 var's?***From:*Muyang Zhang <zmyfudan@gmail.com>

- Prev by Date:
**Re: st: Comparing two response variables** - Next by Date:
**st: opreg and levpet not working** - Previous by thread:
**Re: st: how to encode 2 var's?** - Next by thread:
**st: Analysis fo two count vars** - Index(es):