[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 <>
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 , 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,

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

input code
save `list'

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

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


*   For searches and help try:

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