Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: histogram


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: histogram
Date   Thu, 11 Dec 2003 16:08:00 -0000

Values of what? The densities or the kernel estimates? 

This does densities. 

Syntax 

egen density = density(mpg) [, Width(#) by(varlist) STart(#)] 

*! NJC 1.0.0 28nov2003
program _gdensity 
	version 8
	gettoken type 0 : 0
	gettoken g 0 : 0
	gettoken eqs 0 : 0
	syntax varname(numeric) [if] [in] ///
		[, Width(numlist max=1 >0) BY(varlist) STart(numlist max=1)]

	if "`width'" == "" local width 1 
	
	tempvar ry     
	quietly {
		marksample touse
		if "`start'" == "" { 
			su `varlist' if `touse', meanonly 
			local start = r(min) 
		} 	
		gen double `ry' = ///
			`width' * floor((`varlist' - `start') / `width') 
		bysort `touse' `by' `ry' : gen `type' `g' = _N if `touse' 
		by `touse' `by' : replace `g' = `g' / (`width' * _N) 
	}
end

Nick 
n.j.cox@durham.ac.uk 

Andreas Aschbacher
 
> I put in the following command :
> 
>                 .histogram pos,kdensity       
> 
> but:
>  
> I don't want to get the graph I want all the numeric-values 
> of the "graph"
> in an Ascii-sheet,
> because I want to know the values in the intervals.
> any help will be appreciated 

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index