---------------------------------------------------------------------------------------------------------------- log: C:\Documents and Settings\jlee\My Documents\EC671\poisson_negbin.log log type: text opened on: 8 Nov 2004, 22:27:43 . . use http://fmwww.bc.edu/ec-p/data/wooldridge/CRIME1, clear . . * OLS . . reg narr86 pcnv avgsen tottime ptime86 qemp86 inc86 black hispan born60 Source | SS df MS Number of obs = 2725 -------------+------------------------------ F( 9, 2715) = 23.57 Model | 145.702778 9 16.1891976 Prob > F = 0.0000 Residual | 1864.64438 2715 .686793509 R-squared = 0.0725 -------------+------------------------------ Adj R-squared = 0.0694 Total | 2010.34716 2724 .738012906 Root MSE = .82873 ------------------------------------------------------------------------------ narr86 | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- pcnv | -.131886 .0404037 -3.26 0.001 -.2111112 -.0526609 avgsen | -.0113316 .0122413 -0.93 0.355 -.0353348 .0126717 tottime | .0120693 .0094364 1.28 0.201 -.006434 .0305725 ptime86 | -.0408735 .008813 -4.64 0.000 -.0581544 -.0235925 qemp86 | -.0513099 .0144862 -3.54 0.000 -.079715 -.0229047 inc86 | -.0014617 .000343 -4.26 0.000 -.0021343 -.0007891 black | .3270097 .0454264 7.20 0.000 .2379359 .4160835 hispan | .1938094 .0397156 4.88 0.000 .1159335 .2716853 born60 | -.022465 .0332945 -0.67 0.500 -.0877502 .0428202 _cons | .576566 .0378945 15.22 0.000 .502261 .6508711 ------------------------------------------------------------------------------ . . * Poisson Regression . . poisson narr86 pcnv avgsen tottime ptime86 qemp86 inc86 black hispan born60, nolog Poisson regression Number of obs = 2725 LR chi2(9) = 386.32 Prob > chi2 = 0.0000 Log likelihood = -2248.7611 Pseudo R2 = 0.0791 ------------------------------------------------------------------------------ narr86 | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- pcnv | -.4015713 .0849712 -4.73 0.000 -.5681117 -.2350308 avgsen | -.0237723 .019946 -1.19 0.233 -.0628658 .0153212 tottime | .0244904 .0147504 1.66 0.097 -.0044199 .0534006 ptime86 | -.0985584 .0206946 -4.76 0.000 -.1391192 -.0579977 qemp86 | -.0380187 .0290242 -1.31 0.190 -.0949051 .0188677 inc86 | -.0080807 .001041 -7.76 0.000 -.010121 -.0060404 black | .6608376 .0738342 8.95 0.000 .5161252 .80555 hispan | .4998133 .0739267 6.76 0.000 .3549196 .644707 born60 | -.0510286 .0640518 -0.80 0.426 -.1765678 .0745106 _cons | -.5995888 .0672501 -8.92 0.000 -.7313966 -.467781 ------------------------------------------------------------------------------ . mfx compute Marginal effects after poisson y = predicted number of events (predict) = .32918187 ------------------------------------------------------------------------------ variable | dy/dx Std. Err. z P>|z| [ 95% C.I. ] X ---------+-------------------------------------------------------------------- pcnv | -.13219 .02771 -4.77 0.000 -.186494 -.077886 .357787 avgsen | -.0078254 .00656 -1.19 0.233 -.020691 .00504 .632294 tottime | .0080618 .00485 1.66 0.097 -.001452 .017575 .838752 ptime86 | -.0324437 .00678 -4.79 0.000 -.045725 -.019162 .387156 qemp86 | -.0125151 .0096 -1.30 0.192 -.031333 .006303 2.30903 inc86 | -.00266 .00032 -8.38 0.000 -.003282 -.002038 54.967 black*| .27712 .03844 7.21 0.000 .20178 .35246 .161101 hispan*| .1914481 .03242 5.90 0.000 .1279 .254996 .217615 born60*| -.0166821 .0208 -0.80 0.422 -.057441 .024077 .362569 ------------------------------------------------------------------------------ (*) dy/dx is for discrete change of dummy variable from 0 to 1 . . scalar loglu=e(ll) . * keep the log-likelihood value evaluated at MLE estimator . . * LR test for parameter restriction: . * the null is to exclude: black and hispan . poisson narr86 pcnv avgsen tottime ptime86 qemp86 inc86 born60, nolog Poisson regression Number of obs = 2725 LR chi2(7) = 292.95 Prob > chi2 = 0.0000 Log likelihood = -2295.4452 Pseudo R2 = 0.0600 ------------------------------------------------------------------------------ narr86 | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- pcnv | -.4283928 .0834658 -5.13 0.000 -.5919828 -.2648028 avgsen | -.0185683 .0195768 -0.95 0.343 -.056938 .0198015 tottime | .0258176 .0144725 1.78 0.074 -.0025479 .0541832 ptime86 | -.0896706 .0205936 -4.35 0.000 -.1300334 -.0493079 qemp86 | -.0390197 .029058 -1.34 0.179 -.0959722 .0179329 inc86 | -.0087262 .0010492 -8.32 0.000 -.0107826 -.0066698 born60 | -.0460156 .064013 -0.72 0.472 -.1714789 .0794477 _cons | -.308675 .0573529 -5.38 0.000 -.4210845 -.1962654 ------------------------------------------------------------------------------ . scalar loglr=e(ll) . . scalar LR=2*(loglu-loglr) . dis "the LR statistic is " LR the LR statistic is 93.368272 . scalar p_value=chi2tail(2,LR) . dis "the p-value of LR statistic is " p_value the p-value of LR statistic is 5.313e-21 . . * regression_based test for over-dispersion in the model above . * we need to keep the "stata-score" vector as lamda . quietly poisson narr86 pcnv avgsen tottime ptime86 qemp86 inc86 black hispan born60, score(lamda) . gen zi =( (narr86-lamda)^2-narr86)/(sqrt(2)*lamda) . * run the regression of zi on lamda . reg zi lamda, noconstant Source | SS df MS Number of obs = 2725 -------------+------------------------------ F( 1, 2724) = 209.71 Model | 66.5785935 1 66.5785935 Prob > F = 0.0000 Residual | 864.805691 2724 .317476392 R-squared = 0.0715 -------------+------------------------------ Adj R-squared = 0.0711 Total | 931.384285 2725 .341792398 Root MSE = .56345 ------------------------------------------------------------------------------ zi | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- lamda | -.189421 .0130803 -14.48 0.000 -.2150692 -.1637728 ------------------------------------------------------------------------------ . . ************************************************************* . * Negative binomial regression * . ************************************************************* . . nbreg narr86 pcnv avgsen tottime ptime86 qemp86 inc86 black hispan born60, nolog Negative binomial regression Number of obs = 2725 LR chi2(9) = 266.12 Prob > chi2 = 0.0000 Log likelihood = -2157.628 Pseudo R2 = 0.0581 ------------------------------------------------------------------------------ narr86 | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- pcnv | -.4770963 .1033295 -4.62 0.000 -.6796183 -.2745743 avgsen | -.0173385 .0261171 -0.66 0.507 -.0685272 .0338501 tottime | .0197394 .0192325 1.03 0.305 -.0179557 .0574344 ptime86 | -.1073997 .025074 -4.28 0.000 -.1565439 -.0582555 qemp86 | -.0504884 .0351857 -1.43 0.151 -.1194511 .0184743 inc86 | -.0077126 .0011465 -6.73 0.000 -.0099596 -.0054656 black | .6560406 .0923594 7.10 0.000 .4750195 .8370617 hispan | .5048465 .0895663 5.64 0.000 .3292998 .6803932 born60 | -.046412 .0776384 -0.60 0.550 -.1985804 .1057564 _cons | -.5637368 .0827121 -6.82 0.000 -.7258495 -.4016242 -------------+---------------------------------------------------------------- /lnalpha | -.0738912 .1177617 -.3046999 .1569175 -------------+---------------------------------------------------------------- alpha | .9287728 .1093739 .7373446 1.169899 ------------------------------------------------------------------------------ Likelihood-ratio test of alpha=0: chibar2(01) = 182.27 Prob>=chibar2 = 0.000 . mfx compute Marginal effects after nbreg y = predicted number of events (predict) = .32882893 ------------------------------------------------------------------------------ variable | dy/dx Std. Err. z P>|z| [ 95% C.I. ] X ---------+-------------------------------------------------------------------- pcnv | -.1568831 .03371 -4.65 0.000 -.22296 -.090806 .357787 avgsen | -.0057014 .00859 -0.66 0.507 -.022533 .01113 .632294 tottime | .0064909 .00632 1.03 0.305 -.005905 .018886 .838752 ptime86 | -.0353161 .00822 -4.29 0.000 -.051436 -.019196 .387156 qemp86 | -.016602 .01163 -1.43 0.153 -.039392 .006188 2.30903 inc86 | -.0025361 .00036 -7.09 0.000 -.003237 -.001835 54.967 black*| .2742954 .0483 5.68 0.000 .179621 .36897 .161101 hispan*| .1934841 .03963 4.88 0.000 .11581 .271158 .217615 born60*| -.0151659 .02521 -0.60 0.547 -.064581 .034249 .362569 ------------------------------------------------------------------------------ (*) dy/dx is for discrete change of dummy variable from 0 to 1 . . . ************************************************************* . * Zero-inflated Poisson regression model * . ************************************************************* . . zip narr86 pcnv avgsen tottime ptime86 qemp86 inc86 black hispan born60, inflate(pcnv avgsen tottime ptime86 > qemp86 inc86 black hispan born60) vuong probit nolog Zero-inflated poisson regression Number of obs = 2725 Nonzero obs = 755 Zero obs = 1970 Inflation model = probit LR chi2(9) = 164.47 Log likelihood = -2143.282 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ narr86 | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- narr86 | pcnv | .7021404 .1389722 5.05 0.000 .4297599 .9745209 avgsen | -.0530915 .0266237 -1.99 0.046 -.105273 -.0009101 tottime | .0462388 .0186105 2.48 0.013 .009763 .0827147 ptime86 | .1129759 .0343283 3.29 0.001 .0456937 .180258 qemp86 | -.090848 .0413155 -2.20 0.028 -.171825 -.0098711 inc86 | -.005612 .0013609 -4.12 0.000 -.0082794 -.0029447 black | .430327 .1000625 4.30 0.000 .2342081 .6264458 hispan | .1900477 .1011617 1.88 0.060 -.0082257 .3883211 born60 | -.280749 .0831208 -3.38 0.001 -.4436629 -.1178352 _cons | -.3199173 .1310191 -2.44 0.015 -.5767101 -.0631245 -------------+---------------------------------------------------------------- inflate | pcnv | 1.912247 .2746033 6.96 0.000 1.374034 2.45046 avgsen | -.0464099 .0388137 -1.20 0.232 -.1224833 .0296635 tottime | .03834 .0251275 1.53 0.127 -.010909 .0875889 ptime86 | .1723833 .0287964 5.99 0.000 .1159433 .2288233 qemp86 | -.1146518 .0714934 -1.60 0.109 -.2547762 .0254726 inc86 | .0037749 .0018921 2.00 0.046 .0000666 .0074833 black | -.4262907 .1785358 -2.39 0.017 -.7762144 -.076367 hispan | -.5261584 .1834948 -2.87 0.004 -.8858016 -.1665152 born60 | -.446648 .1531621 -2.92 0.004 -.7468402 -.1464559 _cons | -.8359686 .2966483 -2.82 0.005 -1.417389 -.2545486 ------------------------------------------------------------------------------ Vuong test of zip vs. standard Poisson: z = 5.67 Pr>z = 0.0000 . mfx compute Marginal effects after zip y = predicted number of events (predict) = .40415602 ------------------------------------------------------------------------------ variable | dy/dx Std. Err. z P>|z| [ 95% C.I. ] X ---------+-------------------------------------------------------------------- pcnv | -.1158714 .04449 -2.60 0.009 -.203079 -.028663 .357787 avgsen | -.0117579 .01046 -1.12 0.261 -.032264 .008748 .632294 tottime | .0106749 .00769 1.39 0.165 -.004389 .025739 .838752 ptime86 | .009633 .01463 0.66 0.510 -.019049 .038315 .387156 qemp86 | -.0127554 .01369 -0.93 0.352 -.039597 .014086 2.30903 inc86 | -.0030571 .00042 -7.22 0.000 -.003887 -.002227 54.967 black*| .3128728 .05087 6.15 0.000 .213177 .412568 .161101 hispan*| .1928519 .04106 4.70 0.000 .112368 .273336 .217615 born60*| -.0248501 .02898 -0.86 0.391 -.081654 .031954 .362569 ------------------------------------------------------------------------------ (*) dy/dx is for discrete change of dummy variable from 0 to 1 . . ************************************************************* . * Zero-inflated Negative Binomial regression model * . ************************************************************* . . zinb narr86 pcnv avgsen tottime ptime86 qemp86 inc86 black hispan born60, inflate(pcnv avgsen tottime ptime8 > 6 qemp86 inc86 black hispan born60) vuong probit nolog Zero-inflated negative binomial regression Number of obs = 2725 Nonzero obs = 755 Zero obs = 1970 Inflation model = probit LR chi2(9) = 154.99 Log likelihood = -2108.87 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ narr86 | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- narr86 | pcnv | .3395529 .1714185 1.98 0.048 .0035789 .6755269 avgsen | -.0364481 .0313974 -1.16 0.246 -.0979859 .0250897 tottime | .0328845 .0250528 1.31 0.189 -.0162181 .081987 ptime86 | .1717485 .0476949 3.60 0.000 .0782683 .2652288 qemp86 | -.0479025 .0370636 -1.29 0.196 -.1205457 .0247408 inc86 | -.0065513 .0012282 -5.33 0.000 -.0089585 -.0041441 black | .5556359 .0959076 5.79 0.000 .3676605 .7436113 hispan | .3025678 .0986446 3.07 0.002 .109228 .4959076 born60 | -.2005184 .0826455 -2.43 0.015 -.3625005 -.0385363 _cons | -.5854577 .0865027 -6.77 0.000 -.755 -.4159155 -------------+---------------------------------------------------------------- inflate | pcnv | 3.10853 .5310024 5.85 0.000 2.067785 4.149276 avgsen | -.0570914 .0516546 -1.11 0.269 -.1583325 .0441497 tottime | .0495912 .0390794 1.27 0.204 -.0270031 .1261854 ptime86 | .3077827 .0510809 6.03 0.000 .2076661 .4078994 qemp86 | -.0525505 .09976 -0.53 0.598 -.2480765 .1429756 inc86 | .0035036 .0026179 1.34 0.181 -.0016274 .0086346 black | -.3311215 .2604363 -1.27 0.204 -.8415673 .1793243 hispan | -.5972133 .2818649 -2.12 0.034 -1.149658 -.0447683 born60 | -.6226093 .2327413 -2.68 0.007 -1.078774 -.1664448 _cons | -2.481022 .5574033 -4.45 0.000 -3.573512 -1.388531 -------------+---------------------------------------------------------------- /lnalpha | -.5625126 .1709651 -3.29 0.001 -.897598 -.2274272 -------------+---------------------------------------------------------------- alpha | .5697757 .0974117 .4075474 .7965804 ------------------------------------------------------------------------------ Vuong test of zinb vs. standard negative binomial: z = 5.04 Pr>z = 0.0000 . mfx compute Marginal effects after zinb y = predicted number of events (predict) = .43192418 ------------------------------------------------------------------------------ variable | dy/dx Std. Err. z P>|z| [ 95% C.I. ] X ---------+-------------------------------------------------------------------- pcnv | -.015833 .0709 -0.22 0.823 -.154797 .123131 .357787 avgsen | -.0127584 .01279 -1.00 0.318 -.037817 .0123 .632294 tottime | .0116113 .00999 1.16 0.245 -.007959 .031182 .838752 ptime86 | .0580934 .02351 2.47 0.013 .012007 .10418 .387156 qemp86 | -.0179432 .01489 -1.21 0.228 -.04712 .011233 2.30903 inc86 | -.0030128 .00046 -6.50 0.000 -.003922 -.002104 54.967 black*| .3146348 .05868 5.36 0.000 .199617 .429653 .161101 hispan*| .1711696 .04745 3.61 0.000 .078168 .264171 .217615 born60*| -.0560213 .03385 -1.65 0.098 -.122368 .010325 .362569 ------------------------------------------------------------------------------ (*) dy/dx is for discrete change of dummy variable from 0 to 1 . . * Stata example . . webuse fish, clear . zip count persons livebait, inflate(child camper) vuong probit nolog Zero-inflated poisson regression Number of obs = 250 Nonzero obs = 108 Zero obs = 142 Inflation model = probit LR chi2(2) = 506.29 Log likelihood = -850.3968 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ count | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- count | persons | .8062521 .0453179 17.79 0.000 .7174306 .8950736 livebait | 1.755824 .2444357 7.18 0.000 1.276739 2.234909 _cons | -2.174616 .2858538 -7.61 0.000 -2.734879 -1.614353 -------------+---------------------------------------------------------------- inflate | child | .9658273 .1576773 6.13 0.000 .6567855 1.274869 camper | -.6112131 .2146819 -2.85 0.004 -1.031982 -.1904442 _cons | -.295569 .1869964 -1.58 0.114 -.6620753 .0709372 ------------------------------------------------------------------------------ Vuong test of zip vs. standard Poisson: z = 3.95 Pr>z = 0.0000 . mfx compute Marginal effects after zip y = predicted number of events (predict) = 1.9796995 ------------------------------------------------------------------------------ variable | dy/dx Std. Err. z P>|z| [ 95% C.I. ] X ---------+-------------------------------------------------------------------- persons | 1.596137 .15599 10.23 0.000 1.2904 1.90188 2.528 livebait*| 2.079382 .22751 9.14 0.000 1.63346 2.5253 .864 child | -1.532494 .24688 -6.21 0.000 -2.01637 -1.04862 .684 camper*| .9533159 .32494 2.93 0.003 .316439 1.59019 .588 ------------------------------------------------------------------------------ (*) dy/dx is for discrete change of dummy variable from 0 to 1 . zinb count persons livebait, inflate(child camper) vuong probit nolog Zero-inflated negative binomial regression Number of obs = 250 Nonzero obs = 108 Zero obs = 142 Inflation model = probit LR chi2(2) = 82.87 Log likelihood = -401.1284 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ count | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- count | persons | .9752436 .1032942 9.44 0.000 .7727906 1.177697 livebait | 1.558061 .4119856 3.78 0.000 .7505836 2.365538 _cons | -2.730356 .4763399 -5.73 0.000 -3.663965 -1.796747 -------------+---------------------------------------------------------------- inflate | child | 1.82742 .3852842 4.74 0.000 1.072277 2.582563 camper | -1.158037 .4537525 -2.55 0.011 -2.047376 -.2686987 _cons | -1.528894 .4776438 -3.20 0.001 -2.465059 -.5927295 -------------+---------------------------------------------------------------- /lnalpha | .5044605 .1776896 2.84 0.005 .1561953 .8527256 -------------+---------------------------------------------------------------- alpha | 1.656092 .2942702 1.169055 2.346033 ------------------------------------------------------------------------------ Vuong test of zinb vs. standard negative binomial: z = 5.66 Pr>z = 0.0000 . mfx compute Marginal effects after zinb y = predicted number of events (predict) = 2.4513193 ------------------------------------------------------------------------------ variable | dy/dx Std. Err. z P>|z| [ 95% C.I. ] X ---------+-------------------------------------------------------------------- persons | 2.390633 .41604 5.75 0.000 1.57522 3.20605 2.528 livebait*| 2.391956 .46448 5.15 0.000 1.4816 3.30231 .864 child | -1.355975 .3835 -3.54 0.000 -2.10762 -.604332 .684 camper*| .9280723 .35311 2.63 0.009 .235988 1.62016 .588 ------------------------------------------------------------------------------ (*) dy/dx is for discrete change of dummy variable from 0 to 1 . . . ************************************************************* . * Panel Poisson model (FE, RE) * . ************************************************************* . . webuse ships.dta, clear . . xtpois accident op_75_79 co_65_69 co_70_7 co_75_79, i(ship) ex(service) re nolog Random-effects Poisson regression Number of obs = 34 Group variable (i): ship Number of groups = 5 Random effects u_i ~ Gamma Obs per group: min = 6 avg = 6.8 max = 7 Wald chi2(4) = 50.90 Log likelihood = -74.811217 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ accident | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- op_75_79 | .3827453 .1182568 3.24 0.001 .1509662 .6145244 co_65_69 | .7092879 .1496072 4.74 0.000 .4160633 1.002513 co_70_74 | .8573273 .1696864 5.05 0.000 .5247481 1.189906 co_75_79 | .4958618 .2321316 2.14 0.033 .0408922 .9508313 _cons | -6.591175 .2179892 -30.24 0.000 -7.018426 -6.163924 service | (exposure) -------------+---------------------------------------------------------------- /lnalpha | -2.368406 .8474597 -4.029397 -.7074155 -------------+---------------------------------------------------------------- alpha | .0936298 .0793475 .0177851 .4929165 ------------------------------------------------------------------------------ Likelihood-ratio test of alpha=0: chibar2(01) = 10.61 Prob>=chibar2 = 0.001 . xtpois accident op_75_79 co_65_69 co_70_7 co_75_79, i(ship) ex(service) re normal nolog Random-effects Poisson regression Number of obs = 34 Group variable (i): ship Number of groups = 5 Random effects u_i ~ Gaussian Obs per group: min = 6 avg = 6.8 max = 7 LR chi2(4) = 55.93 Log likelihood = -74.225924 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ accident | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- op_75_79 | .3853861 .1182126 3.26 0.001 .1536936 .6170786 co_65_69 | .7059975 .1495677 4.72 0.000 .4128502 .9991449 co_70_74 | .8486468 .1695192 5.01 0.000 .5163953 1.180898 co_75_79 | .4950771 .2302197 2.15 0.032 .0438548 .9462994 _cons | -6.732638 .1404479 -47.94 0.000 -7.007911 -6.457365 service | (exposure) -------------+---------------------------------------------------------------- /lnsig2u | -1.42662 .5613872 -2.54 0.011 -2.526919 -.3263217 -------------+---------------------------------------------------------------- sigma_u | .4900195 .1375453 .2826744 .8494545 ------------------------------------------------------------------------------ Likelihood-ratio test of sigma_u=0: chibar2(01) = 11.78 Pr>=chibar2 = 0.000 . end of do-file . exit, clear