Statalist The Stata Listserver


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

Re: st: more complicated counting...


From   "Austin Nichols" <austinnichols@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: more complicated counting...
Date   Wed, 16 May 2007 13:18:06 -0400

Jesse--
Most of the relevant user-written contributions are collected in
-egenmore-, but almost any commands for this kind of work other than
-by-, -sort-, -gen, -replace-, and -egen- are just shortcuts
(including -gsort-) and in many cases it is more efficient to work
using only those 5 commands.

Your example is unclear--you seem to assert that the 7 obs belong to
the same surgeon, but the Surgeon variable differs--and your sort
order is not specified in full.  Perhaps the "more" on the subject
line indicates that necessary info is in prior emails; I don't
remember them. Also, why use illegal names for variables?  You are
imposing an extra burden on those who are supposed to help by not
providing a clean example of the beginning data and the target data.

input  Surgeon Hosp Cases NumofHosp
       1      1     4     1
       1      1     4     1
       1      1     4     1
       1      1     4     1
       1      1     2     2
       1      1     2     2
       1      2     1     2
       2      1     4     1
       2      1     4     1
       2      1     4     1
       2      1     4     1
       2      2     2     2
       2      2     2     2
       2      2     1     2
end
g Patient=_n
g nc=-Cases
bys Sur (nc): g kp=(Hosp!=Hosp[_n-1] & _n>1)
by Sur: g keepers=sum(kp)
li, noo sepby(S)


On 5/16/07, Moore, Jesse <Jesse.Moore@vtmednet.org> wrote:
I have data about surgeons who were operated on at different hospitals.
I'd like to keep the information from the hospital with the most cases:
Patient Surgeon Hosp    Cases@hosp      NumofHosp
A               A               1       4               1
B               A               1       4               1
C               A               1       4               1
D               A               1       4               1
E               B               1       2               2
F               B               1       2               2
G               B               2       1               2

I've used gsort so Cases@hosp is in descending order.  I'd like to have
a way of creating a new var (keepers) that would identify patients A-F
but not patient G (second hospital for the surgeon and the hospital with
the fewest cases for that surgeon).  Or, put another way, if the Hosp
changes for a surgeon the indicator var "keepers" goes from a 0 to 1 and
stays that way until the next surgeon.

I realize there are a lot of programs out there (SSC).  How does one go
about searching them for a possible solution to programming challenges?

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