__Title__

**[G-2] twoway__histogram_gen** -- Histogram subroutine

__Syntax__

**twoway__histogram_gen** *varname* [*weight*] [**if** *exp*] [**in** *range*] [**,**
{*discrete_options*|*continuous_options*} *common_options*]

where *discrete_options* are

*discrete_options* Description
-----------------------------------------------------------------
__d__**iscrete** specify data are discrete
**width(***#***)** width of bins in *varname* units
**start(***#***)** theoretical minimum value
-----------------------------------------------------------------

and where *continuous_options* are

*continuous_options* Description
-----------------------------------------------------------------
**bin(***#***)** *#* of bins
**width(***#***)** width of bins in *varname* units
**start(***#***)** lower limit of first bin
-----------------------------------------------------------------

and where *common_options* are

*common_options* Description
-----------------------------------------------------------------
__den__**sity** draw as density (default)
__frac__**tion** draw as fractions
__freq__**uency** draw as frequencies

__gen__**erate(***h x* [, **replace** ]**)** generate variables

**display** display (bin) start and width
----------------------------------------------------------------

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

__Description__

**twoway__histogram_gen** generates a variable containing densities,
frequencies, or fractions of the occurrence of bins (class intervals) of
*varname*.

This tool was written for generating histograms, see **[G-2] graph twoway**
**histogram**.

__Options__

*discrete_options* affect the parameters needed to draw a discrete
histogram. See **[R] histogram** for more details.

*continuous_options* affect the parameters needed to draw a continuous
histogram. See **[R] histogram** for more details.

**density**, **fraction**, and **frequency** are alternatives. They specify whether
you want the histogram scaled to density units, fractional units, or
frequency. **density** is the default. See **[R] histogram** for more
details.

**generate(***h* *x* [**,** **replace**]**)** specifies the names of the variables to
generate. The height of each bin will be placed in *h*, and the center
of each bin will be placed in *x*. The **replace** option indicates that
these variables may be replaced if they already exist.

**display** indicates that a short note be displayed indicating the number of
bins, the lower limit of the first bin, and the width of the bins.
The output displayed is determined by whether the **discrete** option was
specified.

__Stored results__

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

Scalars:

**r(N)** number of observations
**r(bin)** number of bins
**r(width)** common width of the bins
**r(start)** **start()** value or minimum value of *varname*
**r(min)** lower limit of the first non-empty bin
**r(max)** upper limit of the last bin
**r(area)** area of the bars

Macros:

**r(type)** "density", "fraction" or "frequency"