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 at the end of May, and its replacement, statalist.org is already up and running.


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

RE: st: RE: creating an index variable: number of presentations to hospital by participant


From   Nick Cox <n.j.cox@durham.ac.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   RE: st: RE: creating an index variable: number of presentations to hospital by participant
Date   Thu, 28 Oct 2010 12:08:58 +0100

Mitch Abdon had exactly the right idea. I just fleshed it out. 

Nick 
n.j.cox@durham.ac.uk 


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Alison McCarthy
Sent: 28 October 2010 11:49
To: stata
Subject: RE: st: RE: creating an index variable: number of presentations to hospital by participant

Dear Nick,

This is exactly what I was looking for thanks! I had the bysort patient_id year arrivaldate, but was missing the brackets.
Thanks for sending the reading material too.
Really appreciate your advice
Alison 

> From: n.j.cox@durham.ac.uk
> To: statalist@hsphsun2.harvard.edu
> Date: Thu, 28 Oct 2010 10:54:06 +0100
> Subject: RE: st: RE: creating an index variable: number of presentations to hospital by participant
> 
> That is, 
> 
> bysort patient_id year (arrivaldate): gen order_in_year = _n 
> 
> A tutorial on -by:- is included within 
> 
> 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
> 
> which is accessible to all via the Stata Journal website. I got the above text (and other hits) within Stata by 
> 
> . search by, sj 
> 
> -- and if you do that yourself you will get a clickable link to the corresponding .pdf. 
> 
> Nick 
> n.j.cox@durham.ac.uk 
> 
> Mitch Abdon
> 
> You may add the year variable in the -by- prefix. You need to include
> the year variable in the -sort- as well. See "help by".
> 
> Alison McCarthy
> 
> > regarding the formula below. Is there a way to also split this up by year of presentation?
> > This means you have the number of ordered presentations for each participant calculated separately for each year.
> 

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