Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Ranking of variables by means afterr -univar- or -summarize-


From   Joseph Coveney <[email protected]>
To   Statalist <[email protected]>
Subject   Re: st: Ranking of variables by means afterr -univar- or -summarize-
Date   Sat, 27 Jan 2007 19:28:32 +0900

Herve Stolowy wrote:

I have about 50 variables. I get the mean with -univar- [redacted ]
or -summarize-.

univar var1 ... var50
summarize var1 ... var50

Is there a way to rank (descending order) the variables by there mean?

--------------------------------------------------------------------------------

Try the following.

Joseph Coveney


clear
set more off
set seed `=date("2007-01-27", "ymd")'
set obs 100
forvalues i = 1/50 {
   generate float var`i' = `i' + uniform()
}
*
* Begin here
*
collapse (mean) var*
generate byte row = 1
reshape long var, i(row) j(variable_nr)
egen rank = rank(var), field // track or field
*
* Done
*
gsort -var
list , noobs abbreviate(15)
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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index