********************** * Poisson regression * ********************** log using poisson_negbin.log, replace use http://fmwww.bc.edu/ec-p/data/wooldridge/CRIME1, clear * OLS reg narr86 pcnv avgsen tottime ptime86 qemp86 inc86 black hispan born60 * Poisson Regression poisson narr86 pcnv avgsen tottime ptime86 qemp86 inc86 black hispan born60, nolog mfx compute 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 scalar loglr=e(ll) scalar LR=2*(loglu-loglr) dis "the LR statistic is " LR scalar p_value=chi2tail(2,LR) dis "the p-value of LR statistic is " p_value * 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 ************************************************************* * Negative binomial regression * ************************************************************* nbreg narr86 pcnv avgsen tottime ptime86 qemp86 inc86 black hispan born60, nolog mfx compute ************************************************************* * 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 mfx compute ************************************************************* * Zero-inflated Negative Binomial regression model * ************************************************************* zinb narr86 pcnv avgsen tottime ptime86 qemp86 inc86 black hispan born60, inflate(pcnv avgsen tottime ptime86 qemp86 inc86 black hispan born60) vuong probit nolog mfx compute * Stata example webuse fish, clear zip count persons livebait, inflate(child camper) vuong probit nolog mfx compute zinb count persons livebait, inflate(child camper) vuong probit nolog mfx compute ************************************************************* * 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 xtpois accident op_75_79 co_65_69 co_70_7 co_75_79, i(ship) ex(service) re normal nolog xtpois accident op_75_79 co_65_69 co_70_7 co_75_79, i(ship) ex(service) fe nolog