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

st: RE: Re: compiling observations across variables


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Re: compiling observations across variables
Date   Fri, 10 Jan 2003 15:22:23 -0000

Kim Price
>
> > I have 5 variables that list chronic conditions and I
> need to tally the
> > conditions across the variables.  First I tried generating a dummy
> > variable and replacing it with each subset of chronic
> categories across
> > the five variables and then by creating each separately
> and recoding
> > them, however these approaches did not yield accurate
> results.  After
> > looking in the reference manuals and on-line I tried both
> the sum and
> > count commands, however they are also not presenting
> accurate totals
> > either.  I've enclosed excerpts from my Do-files using
> both the dummy
> > variables and "count" command.
> >
> > Any help will be greatly appreciated.
> >
> > Using a dummy variable:
> >
> ># delimit ;
> > gen cc=.;
> >
> > replace cc=1 if chron1cat==1;
> > replace cc=1 if chron2cat==1;
> > replace cc=1 if chron3cat==1;
> > replace cc=1 if chron4cat==1;
> > replace cc=1 if chron5cat==1;
> >
> > replace cc=2 if chron1cat==2;
> > replace cc=2 if chron2cat==2;
> > replace cc=2 if chron3cat==2;
> > replace cc=2 if chron4cat==2;
> > replace cc=2 if chron5cat==2;
> >
> > replace cc=3 if chron1cat==3;
> > replace cc=3 if chron2cat==3;
> > replace cc=3 if chron3cat==3;
> > replace cc=3 if chron4cat==3;
> > replace cc=3 if chron5cat==3;
> >
> > and so forth....
> >
> > Using a dummy variable and recoding:
> >
> ># delimit ;
> > gen cc=.;
> >
> > replace cc=1 if chron1cat==1;
> > replace cc=2 if chron2cat==1;
> > replace cc=3 if chron3cat==1;
> > replace cc=4 if chron4cat==1;
> > replace cc=5 if chron5cat==1;
> >
> > replace cc=6 if chron1cat==2;
> > replace cc=7 if chron2cat==2;
> > replace cc=8 if chron3cat==2;
> > replace cc=9 if chron4cat==2;
> > replace cc=10 if chron5cat==2;
> >
> > and so forth...
> >
> > recode cc
> > 1/5=1
> > 6/10=2
> >
> > and so forth...
> >
> > Using count (I followed a similar format using sum):
> >
> > count if chron1cat==1 | chron2cat==1 | chron3cat==1 |
> chron4cat==1 |
> > chron5cat==1;
> > /*1 "Nervous system" */
> > count if chron1cat==2 | chron2cat==2 | chron3cat==2 |
> chron4cat==2 |
> > chron5cat==2;
> > /* 2 "Headache/migraine" */
> > count if chron1cat==3 | chron2cat==3 | chron3cat==3 |
> chron4cat==3 |
> > chron5cat==3;
> > /* 3 "Problems with vision" */

Kit Baum
>
> Not sure just what you want the end result to be, but all
> these repetitive
> statements are surely not necessary...
>
> local nchron 3
> gen cc=.
> forval i=1/5 {
> 	forval j=1/`nchron' {
> 		replace cc=`j' if chron`i'cat == `j'
> 		}
> 	}
>
> but that will give you one outcome variable which will
> merely have the
> highest value of chron?cat for that observation. To answer
> the question,
> please make clear
> (1) how many possible values there are (nchron above)
> (2) what the outcome should be -- one variable, several
> variables (e.g. can
> the patient be suffering from more than one chronic condition?)

Like Kit, I'm guessing somewhat.

I suspect that you get different results because your
sequences of calculation are not equivalent.

Here is one simple interpretation of what you want.

Your variables chron?cat are in effect a data matrix.

There are various possible approaches to that. The
simplest without using any user-written software
is to -reshape- your data to long. See [R] reshape
and also http://www.stata.com/support/faqs/data/reshape3.html

First, make sure that your data set is -save-d
somewhere.

Second, you need to -rename- those variables
to a stub plus suffix form.

foreach v of var chron?cat {
	rename chron`v'cat chroncat`v'
}

Now I assume you have a patient id somewhere.
If not, create one:

gen id = _n

Now

reshape long chroncat , i(id) j(time)

I am here guessing that 1 2 3 4 5 refer
to different times. If not, you can
supply a sensible name.

Now you should get the information
you want from

tab chroncat time


Nick
[email protected]

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