Bookmark and Share

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, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: tab most frequently occurring

From   Maarten buis <>
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

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) 
*---------------- end example -----------------------
( For more on how to use examples I sent to statalist see: )

Hope this helps,

Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen


*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index