Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: String Match


From   "Austin Nichols" <[email protected]>
To   [email protected]
Subject   Re: st: String Match
Date   Fri, 13 Jun 2008 10:32:47 -0400

Susanna Khavul <[email protected]>:
-merge- and -joinby- will both work fine here; if you want more
detailed advice, I suggest you pose the problem in terms of
cut-and-paste-able code.  The second part of your question concerns
assigning new ID codes to unmatched observations, which seems
dangerous at best.  Nonetheless, it should be easy to replace all
missing ID codes with sequential numbers, if such a thing makes sense
given your data structure. Something like this might work:

use file2
joinby Name using file1, unm(both)
g long obs=_n
sort ID obs
replace ID=ID[_n-1]+1 if mi(ID)

Or it might fail miserably.  Hard to know without more information.

On Fri, Jun 13, 2008 at 9:47 AM, Susanna Khavul <[email protected]> wrote:
> Quite often I have two files where subjects are identified by name.
> The first file has ID codes and then the names, the second does not.
> I need to assign the ID codes to the names in the second file.  Is
> there a quick way of matching the two files and assigning the codes?
> I have thousands of records.   Does stata match on strings through the
> merge command.  I have not been able to do it.
>
> For example
>
> File 1:
>
> ID_Code  Name
> 123         John Smith
> 124         Jane Smith
>
> File 2:
>
> Name
>
> John Smith
> Jane Smith
> Sally Green
>
> I would like File 2 to have:
>
> ID_Code   Name
> 123          John Smith
> 124          Jane Smith
> 125         Sally Green
>
> So here Sally Green is assigned a new ID_Code sequentially.
> *
> *   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index