Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Comparing variable values with a predefined list in other dataset


From   Maarten buis <maartenbuis@yahoo.co.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Comparing variable values with a predefined list in other dataset
Date   Fri, 2 Oct 2009 13:41:02 -0700 (PDT)

--- On Fri, 2/10/09, Andres Gonzalez Rangel wrote:
> I am a Stata 10.1 user.  I have two diagnostic code
> lists: one of them is local and unique (about 4000 codes)
> and the other contains ICD10 codes (in Spanish).  Both
> lists are stored as datasets in .dta files.  I have
> another dataset which contains data from a research, with
> about 6 variables containing the corresponding codes for
> each patient.
>  
> I need a program not as sophisticated as icd9, but capable
> to compare, for every observation, the specified variable's
> value with every single diagnostic code of the list in the
> external dta file, and generate a new variable indicating if
> the variable's value match or not with any diagnostic code
> of the list.
> Such ado exists?  If not, anyone could provide general
> hints to program it?


Sounds like a problem for -merge-. Say you have two files list 
and data, where list is your list of codes and data is your data. 
In the example below I am using -tempfiles- as discussed in http://www.maartenbuis.nl/example_faq/index.html#tempfile , but 
in your case they are real datasets. If you merge the two files, 
a new variable _merge will be created indicating whether the value 
is present in both files, only the master file or only the using 
file. So, in the example below the values 1 and 3 are present in 
both files, while the value 4 is only present in `data' which is 
indicated by the value 1 on _merge, and the value 3 is only 
present in `list' indicated by the value 2 on _merge.

Hope this helps,
Maarten

*------------- begin example ------------
tempfile data list
clear 
input code other_var
      1    1
      3    0
      4    1
end
save `data'

clear
input code
      1
      2
      3
end
save `list'

use `list', clear
sort code
save `ist', replace
use `data', clear
sort code
merge code using `list'
list
*---------- end example --------------
(For more on examples I sent to the Statalist see: 
http://www.maartenbuis.nl/example_faq )

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://www.maartenbuis.nl
--------------------------



      

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



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