/*This program illustrates use of the program Clarify with Poisson and Negative Binomial Regression.*/

/*Poisson Regression */

use "C:\Documents and Settings\B. Dan Wood\My Documents\My Teaching\Maximum Likelihood\Data\shipaccidents.dta", clear

summarize

drop if acc==.

gen logmth=log(months)                                                            /*Generate the log months of service variable. */

constraint define 1 logmth=1                                         /*Define a constraint to replicate Cameron and Trivedi */

/* Following is an example of using Clarify to estimate a poisson regression, calculate poisson expected values, and calculate first differences for the change in expected value when moving an independent variable from minimum to maximum.*/

estsimp poisson acc tb tc td te t6569 t7074 t7579 o7579 logmth, constraints (1) /*Estimate a Poisson regression with constraints */

setx mean                                                                                             /*Set all variables at their means */

simqi,ev                                                                                                /*Report expected value at variable means */

simqi, fd(ev) changex(tb min max)         /*Generate First Differences for change in expected value moving the  type b dummy 0 to 1 */

setx (logmth) mean (tb tc td te t6569 t7074 t7579 o7579)  0                 /*Set logmth at mean, rest to zero*/

simqi, ev                                                                                                                                   /*Report expected value at these values */

simqi, fd(ev) changex(tb min max)                     /*Generate First Differences for change in expected value moving the  type b dummy 0 to 1 */

/*Negative Binomial*/

use "C:\Documents and Settings\B. Dan Wood\My Documents\My Teaching\Maximum Likelihood\Data\shipaccidents.dta", clear

summarize

gen logmth=log(months)                                                            /*Generate the log months of service variable. */

constraint define 1 logmth=1                                         /*Define a constraint to replicate Cameron and Trivedi */

/* Following is an example of using Clarify to estimate a negative binomial regression, calculate expected values, and calculate first differences for the change in expected value when moving an independent variable from minimum to maximum. */

estsimp nbreg acc tb tc td te t6569 t7074 t7579 o7579 logmth, constraints (1) /*Estimate a Poisson regression with constraints */

setx mean                                                                                             /*Set all variables at their means */

simqi,ev                                                                                                /*Report expected value at variable means */

simqi, fd(ev) changex(tb min max)         /*Generate First Differences for change in expected value moving the  type b dummy 0 to 1 */

setx (logmth) mean (tb tc td te t6569 t7074 t7579 o7579)  0                 /*Set logmth at mean, rest to zero*/

simqi, ev                                                                                                                                   /*Report expected value at these values */

simqi, fd(ev) changex(tb min max)                     /*Generate First Differences for change in expected value moving the  type b dummy 0 to 1 */