Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: st: differentiating between groups of records with same date
From
Tim Evans <[email protected]>
To
"'[email protected]'" <[email protected]>
Subject
RE: st: differentiating between groups of records with same date
Date
Wed, 1 Aug 2012 17:32:04 +0100
Nick,
Am grateful as ever for your help.
Best wishes
Tim
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: 01 August 2012 14:55
To: [email protected]
Subject: Re: st: differentiating between groups of records with same date
The Stata Journal article I wrote with Gary Longton has extended
discussion of that too. Perhaps the easiest way to approach this is
something like
egen tag = tag(patient_id proc_type surgery_date)
egen nproc = total(tag), by(patient_id surgery_date)
See p.563 of that article. (A key detail is that Stata Journal
articles more than 3 years old are accessible to all, regardless of
whether you or your institution subscribe to the Journal.)
Nick
On Wed, Aug 1, 2012 at 3:52 AM, Tim Evans <[email protected]> wrote:
>
> Thanks for this. I don't think I want to go with -distinct- and -unique- as I want a flag variable permanently in the dataset. I've worked through the examples in http://www.stata.com/support/faqs/data-management/number-of-distinct-observations/, I'm not sure I'm translating this very well to my scenario, but that's probably my fault in how I'm thinking about it. So I'll give it some space before looking at it again.
Nick Cox
> See
>
> FAQ . . . . . . . . . . . . . . . . . . . Number of distinct observations
> . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox and G. Longton
> 10/08 How do I compute the number of distinct observations?
> http://www.stata.com/support/faqs/data-management/
> number-of-distinct-observations/
>
>
> SJ-12-2 dm0042_1 . . . . . . . . . . . . . . . . Software update for distinct
> (help distinct if installed) . . . . . . N. J. Cox and G. M. Longton
> Q2/12 SJ 12(2):352
> options added to restrict output to variables with a minimum
> or maximum of distinct values
>
> SJ-8-4 dm0042 . . . . . . . . . . . . Speaking Stata: Distinct observations
> (help distinct if installed) . . . . . . N. J. Cox and G. M. Longton
> Q4/08 SJ 8(4):557--568
> shows how to answer questions about distinct observations
> from first principles; provides a convenience command
On Tue, Jul 31, 2012 at 8:27 AM, Tim Evans <[email protected]> wrote:
>> For the following dataset (below) I wish to count the distinct number of proc_type for each patient on a given surgery_date.
>>
>> patient_no cancer_no diag_date surgery_date proc_type
>>> 9512834 0484360 21may1994 21may1994 H1
>>> 9512834 0484358 21may1994 21may1994 H2
>>> 9512834 0483234 26apr2000 21may2000 H1
>>> 9512834 0483233 26apr2000
>>> 0000012 0000012 21Jan1999 21Jan1999 H3
>>> 0000012 0000013 21Jan1999 21Jan1999 H3
>>> 0000012 0000014 21Jan1999 21Jan1999 H3
>>
>>
>> In my snapshot above, patient_no 000012 has 3 cancers, with a surgery_date of 21Jan1999, but only one proc_type - so my count should be 1. In contrast, patient_number 9512834 has 2 cancers with a surgery_date of 21may1994, and has 2 proc_types on 21may1994 - my count should therefore be 2.
>>
>> Or put another way, for each surgery date, how many unique proc_types did each patient have.
>>
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
_DISCLAIMER:
This email and any attachments hereto contains proprietary information, some or all of which may be confidential or legally privileged. It is for the exclusive use of the intended recipient(s) only. If an addressing or transmission error has misdirected this e-mail and you are not the intended recipient(s), please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail or any attachments, as this may be unlawful.
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/