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]

From |
Nick Cox <n.j.cox@durham.ac.uk> |

To |
"'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: RE: rearrange table |

Date |
Fri, 10 Feb 2012 12:24:56 +0000 |

This is shorter than my original (quoted below) and the same length at 10 lines as my second solution. I am sure that Phil and I would both be pleased to see shorter solutions. The bitter-sweet principle is that there is a syntax to produce any table you want: it's just called Stata. Nick n.j.cox@durham.ac.uk Phil Clayton -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) 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/

**Follow-Ups**:**RE: st: RE: rearrange table***From:*Muhammad Akram <aasim548@hotmail.com>

**References**:**st: rearrange table***From:*Nikolaos Pandis <npandis@yahoo.com>

**st: RE: rearrange table***From:*Nick Cox <n.j.cox@durham.ac.uk>

**Re: st: RE: rearrange table***From:*Phil Clayton <philclayton@internode.on.net>

- Prev by Date:
**st: RE: RE: rearrange table** - Next by Date:
**Re: st: RE: RE: rearrange table#2 -add variables** - Previous by thread:
**Re: st: RE: rearrange table** - Next by thread:
**RE: st: RE: rearrange table** - Index(es):