__Title__

**[G-2] twoway__kdensity_gen** -- twoway kdensity subroutine

__Syntax__

**twoway__kdensity_gen** *varname* [*weight*] [**if** *exp*] [**in** *in_range*] **,**
__r__**ange(***range***)**
[ **n(***#***)** __bw__**idth(***#***)** **area(***#***)** __gen__**erate(***yvar* *xvar* [, **replace** ]**)**
__k__**ernel(***kernel***)** *kernel_names* ]

**fweight**s and **aweight**s are allowed; see weights.

__Description__

**twoway__kdensity_gen** was written to help in parsing and generating
variables for **graph twoway kdensity**, see **[G-2] twoway kdensity**.

__Options__

**range(***range***)** specifies the range of values for *xvar*. Here *range* can be a
pair of numbers identifying the minimum and maximum, or *range* can be
a variable. If *range* is a variable, the range is determined by the
values of **r(min)** and **r(max)** after

**. summarize ***range*** if ***exp*** in ***in_range***, meanonly**

**n(***#***)** specifies the number of evaluation points. The default is **n(1)**.

**bwidth(***#***)** specifies the smoothing parameter. This is the same **bwidth()**
option as for **kdensity**, see **[R] kdensity**. The old **width()** option is
also available.

**area(***#***)** specifies the area adjustment. The number is multiplied with the
kernel density estimates when *yvar* is generated. The default value
is **area(1)**.

**generate(***yvar* *xvar* [**,** **replace**]**)** specifies the names of the variables to
generate. The grid of values is placed in *xvar*, and kernel density
estimates are placed in *yvar*. The **replace** option indicates that
these variables may be replaced if they already exist.

**kernel(***kernel***)** specifies kernel weight functions in *kernel* where *kernel*
is defined in **kdensity##kernel**.

*kernel_names* are the names for kernel weight functions accepted by
**kdensity**. This old syntax may not be combined with the new syntax
**kernel()**.

__Stored results__

**twoway__kdensity_gen** stores the following in **r()**:

Scalars:

**r(n)** number of evaluation points
**r(min)** minimum of **range()**
**r(max)** maximum of **range()**
**r(delta)** distance between grid points
**r(area)** area multiplier
**r(width)** smoothing parameter

Macros:

**r(varname)** *varname*
**r(range)** *range* from **range(***range***)** option
**r(kernel)** name of kernel used to compute density estimates