Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: synthetic ZINB

Subject   st: RE: synthetic ZINB
Date   Sun, 5 Jun 2011 19:55:28 -0400 (EDT)

oops. In the code I neglected to amend the label just prior to the synthetic zinb model at the end. The hurdle model caption was retained. I am attaching the correct program, and a similar program for synthetic ZIP. The code
runs OK, it was simply the caption. My apologies.

Joseph Hilbe

-----Original Message-----
From: jhilbe <>
To: statalist <>
Sent: Sun, Jun 5, 2011 4:31 pm
Subject: RE: synthetic ZINB


I happened to see a discussion of synthetic ZINB data on the StataList
digest today. There is an entirely different way to approach this - one
that creates a full synthetic ZINB model.  I wrote about creating
synthetic models in the first volume of the 2010 Stata Journal, and
discuss them much more fully in my recently published, second edition
of "Negative Binomial Regression" (Cambridge University Press, 572
pages). The book discusses most every count model in the literature,
providing both Stata and R code for examples. Output is given in Stata,
except for the final chapter on Bayesian NB models. I also develop a
variety of synthetic count models where it is simple to write your
chosen synthetic predictors as continuous predictors, as binary, or as
multilevel categorical. You may employ as many predictors as you wish,
from an intercept-only model to one with more than 10 predictors if you
wish. The user specifes the desired coefficients for all predictors, as
well as levels of predictor. For NB models you also declare the value
of alpha you wish to model.

It was quite simple to convert the synthetic NB2-logit hurdle model I
give in the book to a zero-inflated NB model, with a logit binary
component. I am attaching it to this message, but provide it below my
signature as well, together with a sample run. Note where the
coefficient values are defined in the comment above active code, but
the actual values are given in the code where indicated.  I made the
predictors here be simple normal variates, but more complex structures
are described in the book, and in the Stata Journal article.

I find synthetic models like this very useful for testing model

Best,  Joseph Hilbe

* Zero inflated Negative binomial with logit as binary component
* Joseph Hilbe  5Jun2011
* LOGIT: x1=-.9, x2=-.1, _c=-.2
* NB2  : x1=.75, n2=-1.25, _c=2, alpha=.5
set obs 50000
set seed 1000
gen x1 = invnorm(runiform())
gen x2 = invnorm(runiform())
gen xb = 2 + 0.75*x1 - 1.25*x2
gen a = .5
gen ia = 1/a
gen exb = exp(xb)
gen xg = rgamma(ia, a)
gen xbg = exb * xg
gen nby = rpoisson(xbg)
gen pi =1/(1+exp(-(.9*x1 + .1*x2+.2)))
gen bernoulli = runiform()>pi
gen zy = bernoulli*nby
rename zy y
zinb y x1 x2, inf(x1 x2) nolog

Zero-inflated negative binomial regression        Number of obs   =
Nonzero obs =
Zero obs =

Inflation model = logit                           LR chi2(2)      =
Log likelihood  = -88361.63                       Prob > chi2     =


           y |      Coef.   Std. Err.      z    P>|z|     [95% Conf.

y            |
          x1 |   .7407043   .0066552   111.30   0.000     .7276604
          x2 |  -1.249479   .0067983  -183.79   0.000    -1.262804
       _cons |   1.996782   .0069297   288.15   0.000       1.9832

inflate      |
          x1 |   .9047498   .0141011    64.16   0.000     .8771121
          x2 |    .095477   .0125229     7.62   0.000     .0709326
       _cons |   .2031966   .0121878    16.67   0.000      .179309

    /lnalpha |  -.6778044   .0153451   -44.17   0.000    -.7078803

       alpha |   .5077305   .0077912                      .4926874


Description: Binary data

Description: Binary data

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index