nbprob.ado and nbprob.hlp copied here from the UCLA website.
Code:
*! version 2.2.1 23oct08, 8dec06 -- pbe *! version 1.0.1 23Mar00 -- pbe program define nbprob version 8.0 syntax , Mean(real) Alpha(real) [ n(integer 10) SAVing(string) Graph notable *] preserve drop _all local n = `n' + 1 quietly set obs `n' local t = 1/`alpha' generate k = _n - 1 generate double term1 = exp(lngamma(k+`t')) / (exp(lngamma(`t'))*(exp(lnfact(k)))) generate double term2 = (`t'/(`t'+`mean'))^`t' generate double term3 = (`mean'/(`mean'+`t'))^k generate double nbprob = term1 * term2 * term3 generate nbcum = sum(nbprob) drop term1 term2 term3 format nbprob nbcum %9.8f format k %4.0f if "`table'" == "" { display display " Negative Binomial Probabilities" display " with mean = `mean' & overdispersion = `alpha'" list } format nbprob %3.2g if "`graph'" ~= "" { twoway connected nbprob k, ylabel(0(.1).3) /// title("Negative binomial: mean = `mean', alpha = `alpha'") /// `options' } if "`saving'" ~= "" { sort k quietly save "`saving'" } restore end
Code:
.- help for ^nbprob^ .- Negative binomial probabilities -------------------------------- ^nbprob^ , ^m^ean(value) ^a^lpha(value) [ ^n^(integer) ^graph sav^ing(filename) graph_options] Description ----------- ^nbprob^ generates negative binomial probabilites. Options ------- ^mean^ the mean of the negative binomial distribution. ^alpha^ the overdispersion parameter. Because the algorithm use 1/alpha, alpha cannot be zero. ^n^ the number of discrete levels to be included. The default value of n is 10. ^graph^ displays a graph of the probabilities. ^saving^ creates a data file with the probabilities. Examples -------- . ^nbprob, mean(2) alpha(.5)^ . ^nbprob, mean(2.3) alpha(1.2) n(10) graph^ Author ------ Philip B. Ender Statistical Computing and Consulting UCLA, Office of Academic Computing ender@@ucla.edu
Comment