Bookmark and Share

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: RE: rearrange table


From   Phil Clayton <[email protected]>
To   [email protected]
Subject   Re: st: RE: rearrange table
Date   Fri, 10 Feb 2012 22:47:20 +1100

-statsby- is very nifty, but in this case you can of course get away with something a little simpler for constructing the results dataset:

sysuse auto, clear
collapse (mean) mean=mpg (sd) sd=mpg (count) n=mpg, by(foreign)
gen ub=mean + invttail((n-1), 0.025) * sd/sqrt(n)
gen lb=mean - invttail((n-1), 0.025) * sd/sqrt(n)

Followed by Nick's:
rename (sd mean lb  ub) (statsd statmean statlb statub)
reshape long stat, i(foreign) string
label def which 1 mean 2 sd 3 lb 4 ub 
encode _j , label(which) gen(which)
label def which 3 "95% limit: lower" 4 "upper", modify
tabdisp which foreign, c(stat) format(%3.2f)

Phil

On 10/02/2012, at 10:21 PM, Nick Cox wrote:

> sysuse auto, clear 
> statsby mean=r(mean) ub=r(ub) lb=r(lb), by(foreign) : ci mpg
> save bystat, replace 
> sysuse auto, clear
> statsby sd=r(sd), by(foreign)  : su mpg
> merge 1:1 foreign using bystat 
> drop _merge
> rename (sd mean lb  ub) (statsd statmean statlb statub)
> reshape long stat, i(foreign) string
> label def which 1 mean 2 sd 3 lb 4 ub 
> encode _j , label(which) gen(which)
> label def which 3 "95% limit: lower" 4 "upper", modify
> tabdisp which foreign, c(stat) format(%3.2f)


*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index