Mark Laflamme
> Variables are named when1 when 2 to when10
> Variable is a string either "BEFORE" or "AFTER" or which neither are
> written(not a missing value)
> A provider has made an order BEFORE or AFTER an encounter
> Providers are categorizd by variable provcode as 1,2,3 or 4
> for particular patients, patient is categorized by string variable
> mrno(8 digits with a dash)
>
> For example
> MRNO when1 when2 when3 ........ when10 provcode
> 1112220-1 BEFORE AFTER 2
> 2223334-5 AFTER AFTER AFTER 3
> 3334445-6
> 4
> 4445556-7 BEFORE BEFORE AFTER AFTER 1
>
> I am trying to ....
> 1) sum the number of BEFORE and AFTER and/or neither for each MRNO
> 2) sum the number of BEFORE and AFTER and/or neither for
> each provcode
> 3) a table for BEFORE and AFTER
>
> For example....
> AFTER
> Yes NO
>
> BEFORE yes 12 34
> No 5 12
> TOTALS
To count "BEFORE" and "AFTER" across -when1-when10-, you
probably should use a loop
gen nbefore = 0
gen after = 0
qui foreach v of var when* {
replace nbefore = nbefore + `v' == "BEFORE"
replace nafter = nafter + `v' == "AFTER"
}
It looks as if you have just one observation
for each MRNO, so that looks like the core of 1).
For 2)
egen nbefore2 = sum(nbefore), by(provcode)
egen nafter2 = sum(nafter2), by(provcode)
tabdisp provcode, c(nbefore2 nafter2)
For 3), what kind of table?
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/