Bookmark and Share

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]

Re: st: Question: Which ICD9 diagnoses occur first for each patient.


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Question: Which ICD9 diagnoses occur first for each patient.
Date   Sat, 12 Jan 2013 09:44:30 +0000

You could something like this:

egen Code = group(ICD9_Code), label
su Code, meanonly
local C = r(max)

forval c = 1/`C' {
           egen firstDate`c' = min(Date / (Code == `c')), by(Patient_ID)
           label var firstDate`c' "`: label (Code) `c''"
}

In practice you evidently only want this for some codes, which would
imply an -if- qualifier on the first statement.

See also

http://www.stata.com/support/faqs/resources/statalist-faq/#spell

@article \{dm0055,
	author = "Cox, N. J.",
	title = "Speaking Stata: Compared with ...",
	journal = "Stata Journal",
	publisher = "Stata Press",
	address = "College Station, TX",
	volume = "11",
	number = "2",
	year = "2011",
	pages = "305-314(10)",
	url = "http://www.stata-journal.com/article.html?article=dm0055";
}

Abstract.  Many problems in data management center on relating values
to values in other observations, either within a dataset as a whole or
within groups such as panels. This column reviews some basic Stata
techniques helpful for such tasks, including the use of subscripts,
summarize, by:, sum(), cond(), and egen. Several techniques exploit
the fact that logical expressions yield 1 when true and 0 when false.
Dividing by zero to yield missings is revealed as a surprisingly
valuable device.

On Fri, Jan 11, 2013 at 5:29 PM, Carl Severson <carlseverson@gmail.com> wrote:

> I have data structured as follows:
>
> Patient_ID    ICD9_Code    Date
>     123               209.1        01/01/1987
>     123               145           11/29/1990
>     123               V46.3        08/04/1991
>     123               89.7          09/08/1991
>     451               V09.1        02/20/2010
>     451               008           02/28/2010
>     451               230.1        10/13/2012
>     451               534           11/01/2012
>     451               908           11/30/2012
>     451               029.8         01/02/2013
>
> I need a method of determining whether or not certain ICD9 codes occur
> before or after other ICD9 codes for each patient.
>
> For instance, for each patient, do ICD9 codes corresponding to
> substance use diagnoses occur before or after ICD9 codes corresponding
> to mental health diagnoses.
>
> Is there some built in functions that I am not aware of that will let
> me do this in STATA? I have been unable to find them if there is. Or
> am I going to have to get down and dirty with MATA?
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index