--- Rachel asked:
> What I'm looking to do is put a histogram in table form:
--- Nick Cox answered:
> At worst, this is two (or three) steps,
>
> 1. create categories
>
> (2. label them nicely)
>
> 3. tabulate
>
> But it can be compressed to one step:
>
> . findit tabcond
>
> . ssc inst tabcond
I was working along Nick's first suggestion and taking Rachel's
question literally: making a table from a histogram. The program below
allows you to do that, the relevant options from -histogram can also be
fed into -histtab-. Installation of this program is discussed in:
http://www.stata.com/statalist/archive/2008-01/msg00511.html
Hope this helps,
Maarten
*------ begin histtab.ado ---------------
*! version 1.0.0 MLB 23Jan2008
program define histtab
version 8.2
syntax varname, *
tempvar h x x2
twoway__histogram_gen mpg, gen(`h' `x') `options'
qui gen byte `x2' = _n if `x' < .
label variable `x2' `"`: variable label `x''"'
local start = r(start)
local rstart : di %9.2g `start'
local bin = r(bin)
local width = r(width)
local end = `start' + `width'
local rend : di %-9.2g `end'
tempname lab
label define `lab' 1 "`rstart' - `rend'"
forvalues i = 2/`r(bin)' {
local start = `end'
local rstart : di %9.2g `start'
local end = `end' + `width'
local rend : di %-9.2g `end'
label define `lab' `i' "`rstart' - `rend'", add
}
label values `x2' `lab'
tabdisp `x2' if `x2' < ., cellvar(`h')
end
*-------------------- end histtab.ado ------------------------------
-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands
visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434
+31 20 5986715
http://home.fsw.vu.nl/m.buis/
-----------------------------------------
__________________________________________________________
Sent from Yahoo! Mail - a smarter inbox http://uk.mail.yahoo.com
*
* 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/