------------------------------------------------------------------------------- help forkdens2-------------------------------------------------------------------------------

Bivariate kernel density estimation

kdens2varnameYvarnameX[ifexp] [inrange] [,n(#)xwidth(#)ywidth(#)saving(name)replacenodraw]

Description

kdens2produces bivariate kernel density estimates using a Gaussian kernel and graphs the result using Adrian Mander'ssurfaceplot 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 ofvarnameX. Ifxwidth()is not specified, then the "optimal" width is used; seekdensity.

ywidth(#)specifies the halfwidth of the kernel, the width of the density window around each point ofvarnameY. Ifywidth()is not specified, then the "optimal" width is used; seekdensity.

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

nodrawspecifies that the 3D graph should not be drawn. However, if thesavingoption is invoked, the resulting data will be saved, and may be fed to another graphing routine such as Stata 12'stwoway contourortwoway contourline.

Examples. webuse grunfeld, clear

. gen linv = log(invest)

. label var linv "Log[Investment]"

. gen lmkt = log(mvalue)

. label var lmkt "Log[Mkt value]" . kdens2 linv lmkt

. kdens2 linv lmkt, n(100)

. kdens2 linv lmkt, xw(.5) yw(.5)

. kdens2 linv lmkt, saving(bivar) replace

AuthorChristopher F. Baum, Boston College, USA baum@bc.edu

AcknowledgementsThe graphics produced by this routne are generated by Adrian Mander's

surfaceroutine. Thanks to Friedrich Huebler and Maria Cecilia Calderon for identifying bugs and Tom Steichen for constructive suggestions.

Also seeOn-line: density