{smcl} {com}{sf}{ul off}{txt}{.-} log: {res}C:\Documents and Settings\jli2\My Documents\Log\MLE_log\negative_binomial.smcl {txt}log type: {res}smcl {txt}opened on: {res}29 Sep 2004, 22:08:30 {txt} {com}. * count data_negative binomial model . * we use the data from stata official website . use http://www.stata-press.com/data/r8/rod93 {txt} {com}. * to generate relevant variables . quietly tab cohort, gen(coh) {txt} {com}. * first run the canned "nbreg" routine . nbreg deaths coh2 coh3 {txt}Fitting Poisson model: Iteration 0: log likelihood = {res} -325.7993{txt} Iteration 1: log likelihood = {res} -325.7993{txt} Fitting constant-only model: Iteration 0: log likelihood = {res}-114.33669{txt} Iteration 1: log likelihood = {res}-110.33038{txt} Iteration 2: log likelihood = {res}-108.56521{txt} Iteration 3: log likelihood = {res}-108.56018{txt} Iteration 4: log likelihood = {res}-108.56018{txt} Fitting full model: Iteration 0: log likelihood = {res}-108.48867{txt} Iteration 1: log likelihood = {res}-108.48841{txt} Iteration 2: log likelihood = {res}-108.48841{txt} Negative binomial regression{col 51}Number of obs{col 67}= {res} 21 {col 51}{txt}LR chi2({res}2{txt}){col 67}= {res} 0.14 {col 51}{txt}Prob > chi2{col 67}= {res} 0.9307 {txt}Log likelihood = {res}-108.48841{col 51}{txt}Pseudo R2{col 67}= {res} 0.0007 {txt}{hline 13}{c TT}{hline 64} deaths {c |} Coef. Std. Err. z P>|z| [95% Conf. Interval] {hline 13}{c +}{hline 64} coh2 {c |} {res} .0591305 .2978419 0.20 0.843 -.5246289 .64289 {txt}coh3 {c |} {res}-.0538792 .2981621 -0.18 0.857 -.6382662 .5305077 {txt}_cons {c |} {res} 4.435906 .2107213 21.05 0.000 4.0229 4.848912 {txt}{hline 13}{c +}{hline 64} /lnalpha {c |} {res}-1.207379 .3108622{col 58}-1.816657 -.5980999 {txt}{hline 13}{c +}{hline 64} alpha {c |} {res} .29898 .0929416{col 58} .1625683 .5498555 {txt}{hline 13}{c BT}{hline 64} Likelihood-ratio test of alpha=0: {help j_chibar:chibar2(01) =}{res} 434.62{txt} Prob>=chibar2 = {res}0.000 {txt} {com}. * user-define MLE procedure . program drop _all {txt} {com}. program define neg_bin_stata {txt} 1{com}. args lnf theta1 theta2 {txt} 2{com}. quietly replace `lnf'=lngamma((1/`theta2')+$ML_y1)-lngamma($ML_y1+1)-lngamma(1/`theta2')+(1/`theta2')*ln(1/(1+`theta2'*exp(`theta1')))+$ML_y1*ln(1-1/(1+`theta2'*exp(`theta1'))) {txt} 3{com}. end {txt} {com}. ml model lf neg_bin_stata ( deaths= coh2 coh3) () {txt} {com}. ml maximize {txt}initial: log likelihood = {res} -{txt} (could not be evaluated) feasible: log likelihood = {res}-1347.5967 {txt}rescale: log likelihood = {res}-130.77236 {txt}rescale eq: log likelihood = {res}-114.30781 {txt}Iteration 0: log likelihood = {res}-114.30781{txt} Iteration 1: log likelihood = {res}-109.97715{txt} Iteration 2: log likelihood = {res}-108.54119{txt} Iteration 3: log likelihood = {res}-108.48846{txt} Iteration 4: log likelihood = {res}-108.48841{txt} Iteration 5: log likelihood = {res}-108.48841{txt} {col 51}Number of obs{col 67}= {res} 21 {col 51}{txt}Wald chi2({res}2{txt}){col 67}= {res} 0.14 {txt}Log likelihood = {res}-108.48841{col 51}{txt}Prob > chi2{col 67}= {res} 0.9306 {txt}{hline 13}{c TT}{hline 64} deaths {c |} Coef. Std. Err. z P>|z| [95% Conf. Interval] {hline 13}{c +}{hline 64} {res}eq1 {txt}{c |} coh2 {c |} {res} .0591305 .2978419 0.20 0.843 -.524629 .64289 {txt}coh3 {c |} {res}-.0538792 .2981621 -0.18 0.857 -.6382662 .5305078 {txt}_cons {c |} {res} 4.435906 .2107214 21.05 0.000 4.0229 4.848912 {txt}{hline 13}{c +}{hline 64} {res}eq2 {txt}{c |} _cons {c |} {res} .2989801 .0929416 3.22 0.001 .1168179 .4811423 {txt}{hline 13}{c BT}{hline 64} {com}. * we get the same result . * the unconditional pdf is given in the description of nbreg command in stata manual . log close {txt}log: {res}C:\Documents and Settings\jli2\My Documents\Log\MLE_log\negative_binomial.smcl {txt}log type: {res}smcl {txt}closed on: {res}29 Sep 2004, 22:11:25 {txt}{.-} {smcl} {txt}{sf}{ul off}