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

st: RE: st : creating a variable that counts frequencies of specific strings in a set of variables


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: st : creating a variable that counts frequencies of specific strings in a set of variables
Date   Thu, 4 Nov 2004 14:45:16 -0000

One basic idea is

gen count43480  = 0 

qui foreach v of var dia2-dia13 { 
	replace count43480 = count43480 + (`v' == 43480) 
} 

but ultimately you will probably be better off with 
a -reshape- 

reshape long dia, i(id) j(which) 
tab dia 

See also -tabm- in -tab_chi- on SSC. 

Nick 
n.j.cox@durham.ac.uk 

Jose Ignacio Pijoan Zubizarreta
 
> I have got a database with several secondary diagnoses 
> dia2-dia13 coded
> according to the ICD9-CM code system (the icd9 commands work 
> well in all of
> them). Some people have a given diagnosis ( e.g. 43840) as 
> dia2 whereas
> other patients can have it included in dia3 or  dia4 an so forth. Each
> individual can have only once a specific diagnostic code. 
> What I would like
> to get is a new variable that counts the frequencies of every single
> diagnostic code across all patients and variables no matter in which
> position it does appear. This way I would be able to say that 
> there are n
> different patients with a specific code ( e.g. 43840) out of the total
> sample.

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index