Develop an algorithm to generate observations from the Negat
Develop an algorithm to generate observations from the NegativeBinomial(r = 3, p = 0.4) distribution. Use your algorithm to generate an observation using the following standard uniform random numbers.
0.148 0.782 0.453 0. 223 0.008
Hint: Convolution method is appropriate here.
Solution
clear set obs 1000 local r = 3 local p = .4 foreach var of newlist nb1-nb`r\' { gen `var\' = int(ln(uniform( ))/ln(1-`p\')) + 1 } egen nb = rsum(nb1-nb`r\') drop nb1-nb`r\'