[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: counting types of diagnoses, and making a table of them, by student |

Date |
Tue, 20 Sep 2005 22:03:42 +0100 |

I think you can get there by doing a -preserve-, a -collapse-, a -list- and then a -restore-. Showing the variable labels is achieveable by putting them in characteristics and using -list, subvarname-. That is a bit much to do routinely, so here is a program sketch: * NJC 1.0.0 20 Sept 2005 program ryanreport version 8 // by() is required; the wildcard carries -list- // options syntax varlist [if] [in] , by(varname) [*] marksample touse qui count if `touse' if r(N) == 0 error 2000 preserve qui keep if `touse' local i = 1 foreach v of local varlist { local label`i' `"`: variable label `v''"' if `"`label`i''"' == "" local label`i' "`v'" local ++i } collapse (sum) `varlist', by(`by') local i = 1 foreach v of local varlist { char `v'[varname] `"`label`i''"' local ++i } list `by' `varlist', noobs subvarname `options' end The syntax for your example would then be something like ryanreport a97 r74 k86 r78, by(studentid) abbrev(12) Nick n.j.cox@durham.ac.uk Christopher W. Ryan, MD > I run a family medicine clerkship for 3rd year medical > students. As the > year goes by, I want to start classifying their patient > visits by ICPC-2 > categories (International Classification of Primary Care.) No doubt > some of you are familiar with it: for example, K86 = > hypertension, R74 = a cold, etc. > > My department uses MS Access for this kind of data tracking, > and I can > get data from there into Stata via StatTransfer. > > I could create a database, one record for each visit, with a > field for > ICPC diagnosis code. Trouble is, each visit could have 2, 3, or more > codes. If I made 3-4 diagnosis fields, into which to enter the ICPC > codes, I don't know how I would tabulate them in Stata, to > determine how > many patients with K86 each student saw; sometimes a K86 > might appear in > variable diagnosis1, other times in variable diagnosis2, etc. > > So I created a bunch of binary (yes/no) fields in the Access > database, > one for each of the most common ICPC codes. Then in Stata, the > following (for example) works great: > > --tabstat a97 r74 k86 r78, by(studentid) statistics(sum) > columns(variables)-- > > It gets me the following (excerpted): > > studentid a97 r74 k86 r78 > > 1780 0 0 0 0 > 1781 0 0 0 0 > 1782 0 0 0 0 > 5555 1 2 1 0 > > Total 1 2 1 0 > > My problem: each variable has a variable label (for example, > a97 is "no > disease"). I would like the variable labels to appear at the tops of > the columns, rather than the variable names, and I can't > figure out how to do this. > > --desc a97-- confirms that the variable label is in place. > > I would appreciate any instructions on how to make the > variable labels > appear, or on my strategy in general. * * 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/

- Prev by Date:
**st: counting types of diagnoses, and making a table of them, by student** - Next by Date:
**st: Bugfix to -moremata- on SSC** - Previous by thread:
**st: counting types of diagnoses, and making a table of them, by student** - Next by thread:
**st: Bugfix to -moremata- on SSC** - Index(es):

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