Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: differentiating between groups of records with same date


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: differentiating between groups of records with same date
Date   Mon, 30 Jul 2012 11:49:30 -0500

bysort patient_no diag_date: gen freq = _N

See also

SJ-2-1  pr0004  . . . . . . . . . . Speaking Stata:  How to move step by: step
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q1/02   SJ 2(1):86--102                                  (no commands)
        explains the use of the by varlist : construct to tackle
        a variety of problems with group structure, ranging from
        simple calculations for each of several groups to more
        advanced manipulations that use the built-in _n and _N


Nick

On Mon, Jul 30, 2012 at 10:20 AM, Tim Evans <Tim.Evans@wmciu.nhs.uk> wrote:
> Hi all,
>
> I have a group of patients who are in a dataset of cancers. Each patient may have more than one cancer diagnosed, and so may be present in my dataset a number of times. Each patient has a unique patient identifier, and each cancer has a unique cancer identifier. Each row of data is cancer specific, but does contain the patient identifier. It is possible that a patient has 2 cancers diagnosed on the same day in my dataset. What I would like to do is generate a flag next to each record to show against each cancer the number of cancers diagnosed on the same day.
>
> My data are like this:
>
> patient_no              cancer_no       diag_date       surgery_date
> 9512834         0484360 21may1994       21may1994
> 9512834         0484358 21may1994       21may1994
> 9512834         0483234 26apr2000       21may2000
> 9512834         0483233 26apr2000
> 0000057         0000057 19jul2009       19jul2009
> 0000060         0000060 02nov2009       24nov2009
> 0000074         0000074 21sep2009       22nov2009
>
>
> For example, patient 9512834 had 2 cancers diagnosed on 21may1994 and so for cancer_no 0484360 and 0484358, I would like to generate a new variable with the value 2 against each record. Similiarly patient 0000057 has only one cancer diagnosed, and so the new variable would contain 1.
>
>

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


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index