help setpoisson



Selection Endogenous Treatment Poisson Model by MSL

Basic syntax

setpoisson (Tvar = varlist1) (Pvar = varlist2) (cvar = varlist3) [if exp] [in range], rep(#) hvector(# # #)

Full syntax

setpoisson (Tvar = varlist1) (Pvar = varlist2) (cvar = varlist13) [if exp] [in range], rep(#) hvector(# # #) method(#) cluster(clustvar) constraints(clist) trace robust hbased mloptions

options Description ----------------------------------------------------------------------------- rep(#) Sets the number of random draws that will be used for calculating the simulated likelihood. hvector(# # #) Controls aspects of the simulation, all three numbers must be integers. The first number sets the number of columns that the vector of random draws will have. The second number picks one column. Finally, the third number sets the number of rows -from the top row onwards- to be discarded from the chosen column. For instance, rep(400) hvec(2 1 100) asks for a 500x2 random vector, to take the first column and to discard the first 100 rows. The resulting 400x1 vector is used for simulating the likelihood. method(#) Type of random draws to be used for simulating the likelihood. Option 1 is the default and indicates that Halton sequences shall be used. Option 2 indicates that a Hammersley set should be used. Finally, option 3 indicates that pseudouniform random numbers should be used. robust The Eicker-Huber-White (sandwich) estimator of the covariance matrix is reported. This option is only valid when used together with the habased option. hbased Maximisation will be performed using analytical first derivatives and numerical second derivatives. cluster(clustvar) Clustered sandwich estimator of the covariance matrix. This option must be used together with the the habased option. constraints(clist) Specifies constraints in the usual way. trace Trace. mloptions Usual mloptions.


setpoisson fits a Selection Endogenous Treatment Poisson model for count data by Maximum Simulated Likelihood.

Important notes

The equation for the treatment variable Tvar always comes first, then the equation for the selection dummy Pvar, and finally the equation for the main count outcome variable cvar. This order should be always observed, otherwise the model will not be correctly estimated or it will produce an error message.

By default the model is fitted by the BHHH method, using analytical first derivatives and an outer product gradient (OPG) approximation of the covariance matrix. The hbased option modifies this default behaviour.

Simulations conducted by the author show that using less than 1,000 delivers slightly underestimated standard errors and that the coverage of the parameters is below the advertised 95%. For these reasons I strongly recommend using at least 1,000 Halton draws to simulate the likelihood.

If Stata is stopped during maximisation for any reason you'll need to drop all macros that are created by petpoisson, otherwise you'll see an error message. In that instance type: . mac drop S_s* S_cat S_x* S_n* S_eqs S_e* S_r* S_i*


. use setpoisson_sdata.dta

. setpoisson (T = x1) (P = T x2) (count = T x3), rep(1600) hvec(1 1 100)

. setpoisson (T = x1) (P = T x2) (count = T x3), rep(1600) hvec(1 1 100) hbased

Marginal effects after estimation

/* At the mean of explanatory variables */ . setpoisson_me [if exp] [in exp]

/* MEs at the mode of explanatory variables */ . setpoisson_me, dmode

/* MEs at the # quantile of the linear predictor */ . setpoisson_me, XBQuantile(0.3)

/* ME for T when count is 2 (v.g. mode of main count) */ . setpoisson_me, cmode(T 2)


Alfonso Miranda ( as part of join work with Massimiliano Bratti.

Conditions of use

setpoisson is not an official Stata command and is an implementation of the methods discussed in Bratti and Miranda (2011). There is no warranty and the author cannot accept any responsability for the use of this software. The entire risk as to the quality and performance is with you. Should the work prove defective, you assume the cost of all necessary servicing, repair, or correction. You may distribute a complete, unmodified copy of this sofware as you received it. No modification or partial copy is allowed. Both the software and the main paper should be cited together.

Suggested citation

Please cite as:

Miranda, A. 2012. setpoisson: Stata module (Mata) to estimate a Selection Endogenous Treatment Poisson Model by MSLL. Available at

Bratti, M. and Miranda, A. 2011. Endogenous treatment effects for count data models with endogenous participation or sample selection. Health Economics 20 (9):1090-1109. Available at

Sofware and paper should be cited together. A copy of the paper is available from the author upon request.