------------------------------------------------------------------------------- help scdensity -------------------------------------------------------------------------------

Univariate self-consistent density estimation

Syntax

scdensity varname [if] [in] [ , generate(newvar1 [newvar2]) n(#) range(# #) nograph name(name[, replace]) ]

Description

scdensity is an implementation of the self-consistent density estimator as described in Bernacchia & Pigolotti (2011). The self-consistent method is a non-parametric way to estimate a density from a number of data points without relying on any a-priori fixation of parameters like smoothing parameters in kernel density estimation, for example.

Options

generate() generates new variable(s). One or two (new) variable names can be specified. If one name is specified, scdensity saves the density estimate in a new variable. If two variables are requested, scdensity saves the density estimate and the grid points, at which the density is evaluated.

n() Number of grid points to be used at which the density is evaluated. If the number of data points is greater than N=1000, the number of grid points defaults to n=1000. If the number of data points is lower than N=1000, the number of grid points defaults to n=N. If a number larger than the actual sample size is requested, n is set to N.

range() Defines the grid range at which the density is to be evaluated. Per default, the endpoints of the evaluation grid are determined by the minimum and maximum value of the actual data points and the range() option can be used to change this default behavior. The input of two numbers is required with the first one being the minimum and the second one being the maximum of the range.

nograph Suppresses the graph. This can be useful in combination with the generate() option.

name() Name of the graph.

Saved results

scdensity saves the following in r():

Scalars r(n_points) Number of evaluation points r(range_min) Minimum grid point r(range_max) Maximum grid point

Dependencies

scdensity requires moremata (Jann 2005), available from SSC. Type -ssc install moremata- in Stata to obtain it. Also, scdensity requires Stata version 9.2 or higher.

Example

. webuse nhanes2

. scdensity height

References

Bernacchia, A. & Pigolotti, S. (2011). Self-Consistent Method For Density Estimation Journal of the Royal Statistical Society B, 73(3), 407-422.

Jann, B. (2005). "MOREMATA: Stata module (Mata) to provide various functions," Statistical Software Components S455001, Boston College Department of Economics, revised 19 Feb 2009.

Acknowledgment

I am thankful to Alberto Bernacchia (Yale University) for helpful discussions and sharing his R code.

Author

Joerg Luedicke Yale University and University of Florida United States email: joerg.luedicke@ufl.edu

Also see