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

Re: st: counting types of diagnoses, and making a table of them,by student


From   Joseph Coveney <jcoveney@bigplanet.com>
To   Statalist <statalist@hsphsun2.harvard.edu>
Subject   Re: st: counting types of diagnoses, and making a table of them,by student
Date   Wed, 21 Sep 2005 11:07:11 +0900

Christopher W. Ryan wrote:

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.)
[Excerpted]
I would appreciate any instructions on how to make the variable labels
appear, or on my strategy in general.

--------------------------------------------------------------------------------

Nick Cox has already given excellent advice on how to create the report and
make the codes appear in Stata from the variable label set up that you
describe.

You asked for comments on your strategy in general:

1. If you find that your students are using a wide variety of ICPC
categories and if you're interested in tracking more than a few, then you
might want to consider normalizing your database a little.  For example, for
the visits, you could have a many-to-many table with one row per student per
IPC code per visit.  The IPC code in this table would be a foreign key
referencing a look-up table of the codes (with a "unique" constraint) and
their labels (declared the primary key).  Your department might already have
this Access table created from the electronic list provided by WONCA.
(Other base tables, for students and visit schedules, can help make data
entry easier, too.)  In this approach, you wouldn't have a wide-shaped
Access table with a multitude of ICPC category columns, but rather a
long-shaped table with the ICPC categories as one column.

And so the ICPC labels would be imported into Stata as a variable and not as
variable labels.  In order to get a Stata listing of the students' visits
with the ICPC label as a variable, you can use something like that
illustrated in the do-file below.  (Half of the do-file below is just
generating the dummy datasets used in the illustration.)

2. If you're using Access, anyway, then consider Access's Report feature.

Joseph Coveney

clear
set more off
set seed `=date("2005-09-20", "ymd")'
tempfile ICPCCodes
input str3 icpc_code str244 icpc_label
"K86" "HYPERTENSION, UNCOMPLICATED"
"B25" "FEAR OF AIDS"
"P74" "ANXIETY DISORDER/ANXIETY STATE"
"P76" "ANXIETY WITH DEPRESSION"
"P01" "ANXIETY NOS"
"K87" "HYPERTENSION WITH COMPLICATIONS"
"W81" "HYPERTENSION IN PREGNANCY"
"K85" "ELEVATED BLOOD PRESSURE"
end
sort icpc_label // Primary key for this look-up table
assert icpc_label != icpc_label[_n-1] in 2/l
save `ICPCCodes' // The ICPC look-up table can be
                // got from Access via Stat/Transfer or Stata's -odbc-.
clear
set obs 10
generate str4 student_id = string(1750 + _n, "%4.0f")
generate byte visit_total = ceil(5 * uniform())
expand visit_total
cross using `ICPCCodes'
generate byte present = uniform() > 0.5
drop if !present
*
* Begin here.
* The dataset should resemble the many-to-many
* Access table for visits for the students mentioned above.
contract student_id icpc_label, zero
sort icpc_label
merge icpc_label using `ICPCCodes'
drop _merge
tostring _freq, replace // In order to be able to put ICPC labels in the
first row
levelsof icpc_code, local(ICPCCode)
reshape wide icpc_label _freq, i(student_id) j(icpc_code) string
set obs `=_N + 1' // Creates the header row at the bottom of the dataset
foreach code of local ICPCCode {
   replace _freq`code' = icpc_label`code'[1] in l // Label from variable
}
sort student_id // Puts the header row (blank Student ID) at the top
replace student_id = "Student ID" in 1
set linesize 240 // Or whatever is needed for the number of ICPCs desired
list student_id _freq*, noobs noheader table separator(0)
exit
* You can do other refinements, too, such as -list- only a subset of
* the ICPC categories for better display, or abbreviate or break up the
* ICPC labels in to smaller chunks for narrower display.

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