It means keep the last observation in each group.
_n goes from 1 to _N. Under -by:- this is _within_
group.
_n and _N are basics and well documented by StataCorp
and others.
. search _n
points to explanations:
[D] functions . . . . . . . . . . . . . . . . . . . . . . . . . Functions
(help functions)
Example . . . . . . . . . . . . . . . Class notes 3.0: Counting from _n to _N
. . . . . . . . . . . . . . . . . . UCLA Academic Technology Services
6/04 http://www.ats.ucla.edu/stat/stata/notes3/countn.htm
SJ-2-1 pr0004 . . . . . . . . . . Speaking Stata: How to move step by: step
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
[email protected]
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of Luc Shum
> Sent: 08 December 2006 22:28
> To: [email protected]
> Subject: st: specify groups within a group
>
>
> Hi,
>
> Thanks for the reply. Much appreciated!
>
> I couldn't quite get my head around the bysort clause where you stated
> "keep if _n==_N". Is it that the clause essentially states, by patient
> section, sort the time entries, and keep the entries where the current
> observation is equal to the total number of observations in
> the dataset? I
> don't understand logic behind this clause. Sorry this is such
> an elementary
> question. ...
>
> Any help is appreciated!
>
> Lucy
>
> Quoting Joseph Coveney <c>:
>
> >Lucy Shum wrote:
> >
> >Hi all, could anybody advise on how to specify in STATA, analysis of
> >specific groups within a category? That is, if I have a
> category called
> >events_mastitis - there are 7 different groups meaning there
> are animals
> >that experienced between 1 - 7 episodes of mastitis within a
> lactation.
> >Say
> >if I only want STATA to analyze, tabulate, create graphs
> of.., say Group
> >1
> >and 5 only. How do I go about doing that?
> >
> >Also, using the example above, how do I go about writing a command so
> >that
> >STATA compares the survival estimates of these 7 groups? Logrank? Is
> >there a
> >modified procedure that deals with comparison of greater
> than 2 groups?
> >
> >
> --------------------------------------------------------------
> ------------------
> >
> >You can use -inlist()- to select groups:
> >
> >tabulate pathogen if inlist(events_mastitis, 1, 5)
> >
> >You can use Stata's survival commands for comparing more than two
> >groups.
> >The example below creates four groups (age categories) and peforms a
> >log-rank test and Cox regression.
> >
> >Joseph Coveney
> >
> >use http://www.stata-press.com/data/r9/catheter, clear
> >bysort patient (time): keep if _n == _N
> >egen byte age_category = cut(age), group(4)
> >stset time, failure(infect)
> >sts test age_category
> >xi: stcox i.age_category
> >exit
> >
> >
> >*
> >* 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/
> >
>
> _________________________________________________________________
> Advertisement: Fresh jobs daily. Stop waiting for the
> newspaper. Search now!
> www.seek.com.au
> http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fninemsn%2Eseek
%2Ecom%2Eau&_t=757263760&_r=Hotmail_EndText_Dec06&_m=EXT
*
* 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/
*
* 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/