Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Saved Results by Group


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: Saved Results by Group
Date   Wed, 7 Aug 2002 13:32:03 +0100

Dan Pregibon

> >Suppose I am summarizing survival data with the command
> "stsum, by(group)"
> >and would like to store particular results of each group
> in a new variable
> >I have generated.  The stored result "r(p50)", for
> example, will give me
> >the 50th percentile of the total set.  Is there a stored
> result for the
> >50th percentile of just group 1 or group 2?

Roger Newson

> No, there isn't. You need to use the -statsby- command of
> official Stata to
> store the results of an analysis for multiple by-groups in
> a data set with
> 1 observation per by-group. See -help statsby- online or
> -[R] statsby- in
> the manuals.
>
> If you are doing analyses with by-groups using estimation
> commands such as
> -stcox-, rather than r-class commands such as -sumby-, you
> can use either
> -statsby- (to generate a data set with 1 observation per
> by-group) or
> -parmby- (to generate a data set with 1 observation per
> parameter per
> by-group and data on confidence limits, P-values and other things).
> -parmby- is part of the -parmest- package, which you can
> download from SSC.
> Type -ssc describe parmest- in Web-aware Stata to find out more.

What -statsby- does is produce a smaller data set based
on groups, and Roger's -parmby- has a similar style. Both
are very nice tools when this is what you want.

Sometimes, however, you want to keep the same data
structure and are well prepared to pay the price that
group statistics are necessarily identical for each
observation in a group.

One general approach to this as follows:

1. Initialise a variable to missing.

gen result = .

2A. Use -levels- from SSC to find the levels of group

levels group, local(levels)

or

2B. Identify which levels you want.

3A.

qui foreach l of local levels {
	... if group == `l'
	replace result = <saved result> if group == `l'
}

or

3B

qui foreach l <your spec> {
	<as before>
}

One merit of this approach is that you can easily
extend by adding more -generate- and -replace- statements.

Nick
[email protected]

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index