program define kdmany version 6 syntax varlist(numeric) [if] [in], [LOG DEBUG /* */ BIweigh COSine EPan GAUss PARzen RECtang TRIangl /* */ N(integer 1) Width(real 0) AT(varname) /* */ ZEROES Symbol(str) Connect(str) SOrt *] local kernels "biweigh cosine epan gauss parzen rectang triangl" tokenize `kernels' tempname s scalar `s'=0 local k=1 while `k'<=7 { scalar `s'=`s'+("```k'''"~="") local k=`k'+1 } if `s'>=2 { di in red "only one type of kernel may be specified" exit 198 } tokenize `varlist' preserve local kdopt "`biweigh' `cosine' `epan' `gauss' `parzen' `rectang' `triangl'" if "`n'"~="" { local kdopt "`kdopt' n(`n')" } if "`width'"~="" { local kdopt "`kdopt' width(`width')" } if "`at'"~="" { local kdopt "`kdopt' at(`at')" } if "`log'"=="" & "`zeroes'"~="" { di in red "zeroes may not be specified without log" exit 198 } qui { marksample touse keep if `touse' local cond if "`if'"~="" | "`in'"~="" { local cond `"Cond."' } if "`zeroes'"~="" { local max=-1e12 local min=1e12 } /* to create a kernel thing for zeroes logarithmed */ local k=1 while "``k''"~="" { tempvar y`k' x`k' d`k' if "`log'"~="" { g double `y`k''=log(``k'') if "`zeroes'"~="" { qui sum `y`k'' if `min'>r(min) {local min=r(min)} if `max'