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: tab most frequently occurring
From
Maarten buis <[email protected]>
To
[email protected]
Subject
Re: st: tab most frequently occurring
Date
Wed, 17 Mar 2010 14:39:17 +0000 (GMT)
--- On Wed, 17/3/10, Richard Goldstein wrote:
> I want to -tabulate- a variable with many (hundreds if not
> thousands of) different values; but, I only want to see (a)
> the 20 (say) most frequently occurring values and then (b)
> I want a row for "all others" and then (c) I want a grand
> total row
Maybe something along these lines:
*----------- begin example -----------------
sysuse nlsw88, clear
preserve
contract wage, nomiss
gsort -_freq
gen long sum = sum(_freq)
clonevar tobetabbed = wage in 1/20
replace tobetabbed = .a in 21
replace tobetabbed = .b in 22
gen freq = _freq in 1/20
replace freq = sum[_N] - sum[20] in 21
replace freq = sum[_N] in 22
local vallab : value label wage
tempname tablab
if "`vallab'" == "" {
label define `tablab' .a "rest" .b "total"
label value tobetabbed `tablab'
}
else {
label define `vallab' .a "rest" .b "total", add
label value tobetabbed `vallab'
}
tabdisp tobetabbed in 1/22, cellvar(freq)
restore
*---------------- end example -----------------------
( For more on how to use examples I sent to statalist see:
http://www.maartenbuis.nl/stata/exampleFAQ.html )
Hope this helps,
Maarten
--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany
http://www.maartenbuis.nl
--------------------------
*
* 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/