program define _lnbessel /* var = p, k(k) */
	version 7

	syntax newvarname =/exp [if] [in] [, k(varname) ]

	tempvar bm1 bm2 touse
	mark `touse' `if' `in'

	qui gen double `bm2' = 1 if `touse'
	qui gen double `bm1' = 1 if `touse'
	qui gen double `varlist' = 1 if `touse'
	local i 2
	while 1 {
		qui replace `varlist' = (2*`i'-3)*(`exp')*`bm1' + `bm2' /*
			*/ if `touse' & round(`k',1)>=`i'
		qui replace `bm2' = `bm1' if `touse' & round(`k',1)>=`i'
		qui replace `bm1' = `varlist' if `touse' & round(`k',1)>=`i'
		local i = `i' + 1
		capture assert `k'<`i' if `touse'
		if _rc==0 {
			continue, break
		}
	}
	qui replace `varlist' = ln(`varlist') if `touse'
end