Note: This chapter uses a suite of commands, called spost, written by J. Scott Long and Jeremy Freese. The commands must be downloaded prior to their use, and this can be done by typing search spost in the Stata command line (see How can I use the search command to search for programs and get additional help? for more information about using search).
Figure 8.2, page 220.
use https://stats.idre.ucla.edu/stat/stata/examples/long/couart2.dta, clear poisson art Iteration 0: log likelihood = -1742.5735 Iteration 1: log likelihood = -1742.5735 Poisson regression Number of obs = 915 LR chi2(0) = 0.00 Prob > chi2 = . Log likelihood = -1742.5735 Pseudo R2 = 0.0000 ------------------------------------------------------------------------------ art | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _cons | .5264408 .0254082 20.72 0.000 .4766416 .57624 ------------------------------------------------------------------------------ prcounts psn, plot max(9) /*prcounts is from spostado */ label var psnobeq "Observed Proportion" label var psnpreq "Poisson Prediction" label var psnval "# of articles" graph twoway (scatter psnobeq psnpreq psnval, connect (l l) xlabel(0(1)9) ytitle("Probability"))
Table 8.1, page 227.
gen lnart = ln(art + .5) label var lnart "Log of (Art + .5)" describe Contains data from https://stats.idre.ucla.edu/stat/stata/examples/long/couart2.dta obs: 915 Academic Biochemists / S Long vars: 34 30 Jan 2001 10:49 size: 114,375 (89.0% of memory free) (_dta has notes) ------------------------------------------------------------------------------- storage display value variable name type format label variable label ------------------------------------------------------------------------------- art byte %9.0g Articles in last 3 yrs of PhD fem byte %9.0g sexlbl Gender: 1=female 0=male mar byte %9.0g marlbl Married: 1=yes 0=no kid5 byte %9.0g Number of children < 6 phd float %9.0g PhD prestige ment byte %9.0g Article by mentor in last 3 yrs psnrate float %9.0g Predicted rate from poisson psnpr0 float %9.0g Pr(y=0) from poisson psnpr1 float %9.0g Pr(y=1) from poisson psnpr2 float %9.0g Pr(y=2) from poisson psnpr3 float %9.0g Pr(y=3) from poisson psnpr4 float %9.0g Pr(y=4) from poisson psnpr5 float %9.0g Pr(y=5) from poisson psnpr6 float %9.0g Pr(y=6) from poisson psnpr7 float %9.0g Pr(y=7) from poisson psnpr8 float %9.0g Pr(y=8) from poisson psnpr9 float %9.0g Pr(y=9) from poisson psncu0 float %9.0g Pr(y=0) from poisson psncu1 float %9.0g Pr(y<=1) from poisson psncu2 float %9.0g Pr(y<=2) from poisson psncu3 float %9.0g Pr(y<=3) from poisson psncu4 float %9.0g Pr(y<=4) from poisson psncu5 float %9.0g Pr(y<=5) from poisson psncu6 float %9.0g Pr(y<=6) from poisson psncu7 float %9.0g Pr(y<=7) from poisson psncu8 float %9.0g Pr(y<=8) from poisson psncu9 float %9.0g Pr(y<=9) from poisson psnprgt float %9.0g Pr(y>9) from poisson psnval float %9.0g # of articles psnobeq float %9.0g Poisson Prediction psnpreq float %9.0g Predicted Pr(y=k) from poisson psnoble float %9.0g Observed Pr(y<=k) from poisson psnprle float %9.0g Predicted Pr(y<=k) from poisson lnart float %9.0g Log of (Art + .5) ------------------------------------------------------------------------------- Sorted by: art Note: dataset has changed since last saved sum Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- art | 915 1.692896 1.926069 0 19 fem | 915 .4601093 .4986788 0 1 mar | 915 .6622951 .473186 0 1 kid5 | 915 .495082 .76488 0 3 phd | 915 3.103109 .9842491 .755 4.62 -------------+-------------------------------------------------------- ment | 915 8.767213 9.483916 0 77 psnrate | 915 1.692896 0 1.692896 1.692896 psnpr0 | 915 .1839859 0 .1839859 .1839859 psnpr1 | 915 .311469 0 .311469 .311469 psnpr2 | 915 .2636423 0 .2636423 .2636423 -------------+-------------------------------------------------------- psnpr3 | 915 .148773 0 .148773 .148773 psnpr4 | 915 .0629643 0 .0629643 .0629643 psnpr5 | 915 .0213184 0 .0213184 .0213184 psnpr6 | 915 .006015 0 .006015 .006015 psnpr7 | 915 .0014547 0 .0014547 .0014547 -------------+-------------------------------------------------------- psnpr8 | 915 .0003078 0 .0003078 .0003078 psnpr9 | 915 .0000579 0 .0000579 .0000579 psncu0 | 915 .1839859 0 .1839859 .1839859 psncu1 | 915 .4954549 0 .4954549 .4954549 psncu2 | 915 .7590972 0 .7590972 .7590972 -------------+-------------------------------------------------------- psncu3 | 915 .9078703 0 .9078703 .9078703 psncu4 | 915 .9708346 0 .9708346 .9708346 psncu5 | 915 .992153 0 .992153 .992153 psncu6 | 915 .9981681 0 .9981681 .9981681 psncu7 | 915 .9996227 0 .9996227 .9996227 -------------+-------------------------------------------------------- psncu8 | 915 .9999305 0 .9999305 .9999305 psncu9 | 915 .9999884 0 .9999884 .9999884 psnprgt | 915 .0000116 0 .0000116 .0000116 psnval | 10 4.5 3.02765 0 9 psnobeq | 10 .0993443 .1139905 .0010929 .3005464 -------------+-------------------------------------------------------- psnpreq | 10 .0999988 .1187734 .0000579 .311469 psnoble | 10 .8328962 .2308122 .3005464 .9934426 psnprle | 10 .8307106 .2791442 .1839859 .9999884 lnart | 915 .4399161 .8566493 -.6931472 2.970414
Table 8.2 , page 228.
quietly reg lnart fem mar kid5 phd ment listcoef regress (N=915): Unstandardized and Standardized Estimates Observed SD: .8566493 SD of Error: .81457396 ------------------------------------------------------------------------------- lnart | b t P>|t| bStdX bStdY bStdXY SDofX -------------+----------------------------------------------------------------- fem | -0.13457 -2.349 0.019 -0.0671 -0.1571 -0.0783 0.4987 mar | 0.13283 2.043 0.041 0.0629 0.1551 0.0734 0.4732 kid5 | -0.13315 -3.275 0.001 -0.1018 -0.1554 -0.1189 0.7649 phd | 0.02550 0.896 0.371 0.0251 0.0298 0.0293 0.9842 ment | 0.02542 8.607 0.000 0.2411 0.0297 0.2814 9.4839 ------------------------------------------------------------------------------- quietly poisson art fem mar kid5 phd ment listcoef poisson (N=915): Factor Change in Expected Count Observed SD: 1.926069 ---------------------------------------------------------------------- art | b z P>|z| e^b e^bStdX SDofX -------------+-------------------------------------------------------- fem | -0.22459 -4.112 0.000 0.7988 0.8940 0.4987 mar | 0.15524 2.529 0.011 1.1679 1.0762 0.4732 kid5 | -0.18488 -4.607 0.000 0.8312 0.8681 0.7649 phd | 0.01282 0.486 0.627 1.0129 1.0127 0.9842 ment | 0.02554 12.733 0.000 1.0259 1.2741 9.4839 ---------------------------------------------------------------------- quietly nbreg art fem mar kid5 phd ment listcoef nbreg (N=915): Factor Change in Expected Count Observed SD: 1.926069 ---------------------------------------------------------------------- art | b z P>|z| e^b e^bStdX SDofX -------------+-------------------------------------------------------- fem | -0.21642 -2.978 0.003 0.8054 0.8977 0.4987 mar | 0.15049 1.833 0.067 1.1624 1.0738 0.4732 kid5 | -0.17642 -3.325 0.001 0.8383 0.8738 0.7649 phd | 0.01527 0.424 0.672 1.0154 1.0151 0.9842 ment | 0.02908 8.381 0.000 1.0295 1.3176 9.4839 -------------+-------------------------------------------------------- ln alpha | -0.81730 alpha | 0.44162 SE(alpha) = 0.05297 ---------------------------------------------------------------------- LR test of alpha=0: 180.20 Prob>=LRX2 = 0.000 ----------------------------------------------------------------------
Figure 8.4, page 229.
quietly poisson art fem mar kid5 phd ment prcounts psm, plot max(9) label var psmpreq "PRM" label var psmobeq "Observed" label var psmval "# of articles" quietly nbreg art fem mar kid5 phd ment prcounts nbm, plot max(9) label var nbmpreq "NBM" graph twoway (scatter psmobeq psmpreq nbmpreq psmval, connect(l l l) xlabel(0(1)9) ytitle("Probability"))
Figure 8.8, page 238.
quietly poisson art fem mar kid5 phd ment prgen ment, from(0) to(50) rest(mean) gen(pm) n(11) poisson: Predicted values as ment varies from 0 to 50. fem mar kid5 phd ment x= .46010929 .66229508 .49508197 3.1031093 8.7672131 label var pmp0 "PRM" quietly nbreg art fem mar kid5 phd ment prgen ment, from(0) to(50) rest(mean) gen(nb) n(11) nbreg: Predicted values as ment varies from 0 to 50. fem mar kid5 phd ment x= .46010929 .66229508 .49508197 3.1031093 8.7672131 label var nbp0 "NBM" graph twoway (scatter pmp0 nbp0 nbx, c(l l l) xtitle("Mentor's Articles") /// ytitle("Pr(Zero Articles)") msymbol(Sh Oh))
Table 8.3, page 246.
zip art fem mar kid5 phd ment, inflate(fem mar kid5 phd ment) nolog Zero-inflated poisson regression Number of obs = 915 Nonzero obs = 640 Zero obs = 275 Inflation model = logit LR chi2(5) = 78.56 Log likelihood = -1604.773 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ art | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- art | fem | -.2091446 .0634047 -3.30 0.001 -.3334155 -.0848737 mar | .103751 .071111 1.46 0.145 -.035624 .243126 kid5 | -.1433196 .0474293 -3.02 0.003 -.2362793 -.0503599 phd | -.0061662 .0310086 -0.20 0.842 -.066942 .0546096 ment | .0180977 .0022948 7.89 0.000 .0135999 .0225955 _cons | .640839 .1213072 5.28 0.000 .4030814 .8785967 -------------+---------------------------------------------------------------- inflate | fem | .1097465 .2800813 0.39 0.695 -.4392028 .6586958 mar | -.3540107 .3176103 -1.11 0.265 -.9765155 .2684941 kid5 | .2171001 .196481 1.10 0.269 -.1679956 .6021958 phd | .0012702 .1452639 0.01 0.993 -.2834418 .2859821 ment | -.134111 .0452461 -2.96 0.003 -.2227918 -.0454302 _cons | -.5770618 .5093853 -1.13 0.257 -1.575439 .421315 ------------------------------------------------------------------------------ zinb art fem mar kid5 phd ment, inflate(fem mar kid5 phd ment) nolog Zero-inflated negative binomial regression Number of obs = 915 Nonzero obs = 640 Zero obs = 275 Inflation model = logit LR chi2(5) = 67.97 Log likelihood = -1549.991 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ art | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- art | fem | -.1955068 .0755926 -2.59 0.010 -.3436655 -.0473481 mar | .0975826 .084452 1.16 0.248 -.0679402 .2631054 kid5 | -.1517325 .054206 -2.80 0.005 -.2579744 -.0454906 phd | -.0007001 .0362696 -0.02 0.985 -.0717872 .0703869 ment | .0247862 .0034924 7.10 0.000 .0179412 .0316312 _cons | .4167466 .1435962 2.90 0.004 .1353032 .69819 -------------+---------------------------------------------------------------- inflate | fem | .6359328 .8489175 0.75 0.454 -1.027915 2.299781 mar | -1.499469 .9386701 -1.60 0.110 -3.339228 .3402909 kid5 | .6284274 .4427825 1.42 0.156 -.2394105 1.496265 phd | -.0377153 .3080086 -0.12 0.903 -.641401 .5659705 ment | -.8822932 .3162276 -2.79 0.005 -1.502088 -.2624984 _cons | -.1916865 1.322821 -0.14 0.885 -2.784368 2.400995 -------------+---------------------------------------------------------------- /lnalpha | -.9763565 .1354679 -7.21 0.000 -1.241869 -.7108443 -------------+---------------------------------------------------------------- alpha | .3766811 .0510282 .288844 .4912293 ------------------------------------------------------------------------------