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 |
Rieza Soelaeman <rsoelaeman@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: RE: Manipulating tabulation output so rows are sorted by value of column... |

Date |
Fri, 10 Feb 2012 16:50:37 -0600 |

Nick--thank you rhs On Thu, Feb 9, 2012 at 5:57 PM, Nick Cox <n.j.cox@durham.ac.uk> wrote: > -table- is at first sight a dead end here, as there is no such sorting option. > > Although I can imagine devious work-arounds, I think you will get most flexibility just by creating a reduced dataset and -sort-ing in exactly the way the want. > > You said increasing order, but your examples are decreasing, but you can have it either way. > > Consider > > . sysuse auto, clear > > . drop if missing(rep78) > > . collapse mpg , by(foreign rep78) > > . gsort foreign -mpg > > . format mpg %2.1f > > . l, sepby(foreign) noobs > > +-------------------------+ > | rep78 foreign mpg | > |-------------------------| > | 5 Domestic 32.0 | > | 1 Domestic 21.0 | > | 2 Domestic 19.1 | > | 3 Domestic 19.0 | > | 4 Domestic 18.4 | > |-------------------------| > | 5 Foreign 26.3 | > | 4 Foreign 24.9 | > | 3 Foreign 23.3 | > +-------------------------+ > > > Nick > n.j.cox@durham.ac.uk > > Rieza Soelaeman > > > Supposing I have the following data: > Name Year Value > AA 1990 985 > AA 1990 246 > AA 2000 237 > AA 2000 560 > BB 1990 457 > BB 1990 742 > BB 2000 985 > BB 2000 154 > CC 1990 799 > CC 1990 656 > CC 2000 980 > CC 2000 812 > > > And I want to see results displayed as follows (take the average of > the value for each name, and display by year, sorted by mean(value)): > > YEAR==1990 > Name mean(value) > CC 727.5 > AA 615.5 > BB 599.5 > > and > > YEAR==2000 > Name mean(value) > AA 599.5 > BB 569.5 > CC 357.5 > > > How would I modify my existing code such that the results are > displayed in increasing order of mean(value), > so I can see easily which name had the highest mean(value)? > > .table Name if Year==1990, contents(mean value) > .table Name if Year==2000, contents(mean value) > > Is there an in-line sort option that goes with the table command? > > Right now the result is not displayed in any specific way. > > * > * 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/ * * 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/

**References**:**st: Manipulating tabulation output so rows are sorted by value of column...***From:*Rieza Soelaeman <rsoelaeman@gmail.com>

**st: RE: Manipulating tabulation output so rows are sorted by value of column...***From:*Nick Cox <n.j.cox@durham.ac.uk>

- Prev by Date:
**RE: st: Situation where multiple imputation may be of no use?** - Next by Date:
**st: how to construct change in earnings since last election** - Previous by thread:
**st: RE: Manipulating tabulation output so rows are sorted by value of column...** - Next by thread:
**Re: st: confirmatory factor analysis programs [was: RE: Stata support]** - Index(es):