help for kdens2

Bivariate kernel density estimation

kdens2
varnameY
varnameX
[if exp]
[in range]
[, n(#)
xwidth(#)
ywidth(#)
saving(name)
replace nodraw color {cmd:*)
]

Description

kdens2 produces bivariate kernel density estimates using a Gaussian kernel.
For version 12.1 of Stata, a graph is produced with twoway contourline, or optionally
twoway contour. For versions 10 and 11 of Stata, graphs the result using
Adrian Mander's surface plot routine. If Y- and X-variable labels are available,
they are used to label the graph.

Options

n(#) specifies the number of points on the Y- and X-axes at which the density estimate is to be evaluated. The default is min(_N,50).

xwidth(#) specifies the halfwidth of the kernel, the width of the density window around each point of varnameX.
If xwidth() is not specified, then the "optimal" width is used; see kdensity.

ywidth(#) specifies the halfwidth of the kernel, the width of the density window around each point of varnameY.
If ywidth() is not specified, then the "optimal" width is used; see kdensity.

saving(name) causes the graph to be saved as name.gph.
If this graph already exists, the replace option must be used. The option also causes the data underlying the
graph to be written to name.dta. If this file already exists,
the replace option must be used.

nodraw specifies that the 3D graph should not be drawn. However, if the saving option is invoked,
the resulting data will be saved.

color specifies, for Stata version 12.1, that twoway contour is to be used
rather than twoway contourline.

* indicates that any options appropriate for twoway contourline or twoway contour
may be given.

Examples

. webuse grunfeld, clear

. gen linv = log(invest)

label var linv "Log[Investment]:. label var linv "Log[Investment]"

. gen lmkt = log(mvalue)

. label var lmkt "Log[Mkt value]"

. kdens2 linv lmkt

. kdens2 linv lmkt, levels(20)

. kdens2 linv lmkt, levels(20) color

. kdens2 linv lmkt, saving(bivar) replace

Author

Christopher F. Baum, Boston College, USA

baum@bc.edu

Acknowledgements

For Stata versions 10 and 11, the graphics produced by this routine are generated by Adrian Mander's
surface routine. Thanks to Friedrich Huebler and Maria Cecilia Calderon for
identifying bugs and Tom Steichen for constructive suggestions.

Also see

On-line: density