help for egen kweight

Extension to generate kernel weights

egen [type] newvar =
kweight(varname) [if exp] [in range]
[, options]

syntax newvarname =/exp [if] [in] , bw(real) pofr(real) [kernel(str)]

Description

egen kweight creates newvar of the optionally specified storage type
equal to kweight(varname). Using a specified bandwidth, kernel function and point of reference, This module produces the normalized kernel weights.

Main

bw(#) Indicates bandwidth to be used for estimating the kernel weights

pofr(#) Indicates a point of reference that will be used to estimate the kernel weights. Points closer to the pofr will have a higher weight

kernel(kernel) Indicates which kernel function to be used in the process. Default is Gaussian Kernel. All kernel

kernel

gaussian Gaussian kernel function; The default

epan Epanechnikov kernel function

epan2 alternative Epanechnikov kernel function

biweight biweight kernel function

cosine cosine trace kernel function

parzen Parzen kernel function

rectan rectangle kernel function

trian triangle kernel function

Additional Kernel functions:

logistic Logistic kernel function

tricube Tricube kernel function

triweight Triweight kernel function

Kernel functions for discrete data. All BW must lie between 0 and 1 for this kernels

liracine Li-Racine Kernel for unordered Data

liracine2 Li-Racine Kernel for ordered Data

habbena Habbena kernel for ordered data

logdis Log distance kernel for ordered data

dtrian Triangular distance kernel for ordered data

Description

The function kweight creates the normalized kernel weights based on a defined kernel function, a selected bandwidth and a given point of reference.

Given this information, the weights are created as follows:

First, it creates an auxiliary variable z defined as: z=(x-pofr)/bw

With this information, the normalized kernel weight is defined as: kw=kernel(z)/kernel(0). where kernel is any of the kernel functions indicated above.

For discrete ordered data, distance from the point of interest are weighted equally.

Examples

webuse nlswork, clear
set seed 1
replace age=age+rnormal()*.5
egen kwage_30a=kweight(age), pofr(30) bw(3)
egen kwage_30b=kweight(age), pofr(30) bw(3) kernel(epan)
egen kwage_30c=kweight(age), pofr(30) bw(6) kernel(biweight)

Visualizing the weights:
line kwage_30* age, sort

Author

Fernando Rios-Avila

Levy Economics Institute of Bard College

Blithewood-Bard College

Annandale-on-Hudson, NY

friosavi@levy.org