Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: ML and Fixed-Effects Zero-Inflated Poisson


From   Skipper Seabold <[email protected]>
To   [email protected]
Subject   st: ML and Fixed-Effects Zero-Inflated Poisson
Date   Tue, 17 Sep 2013 18:26:02 -0400

Hi All,

I've found the implementation of the fixed-effects zero-inflated Poisson
model from Majo and van Soest [1]. To the best of my knowledge, I've copied
the program they provided and tried to run it on the patents data example
from Cameron and Trivedi's Microeconometrics. However, no matter what I've
tried ml can't find feasible starting values. It's the same across several
datasets I've tried.

So far I can't find a mistake in the transcription. The only line I'm not
sure about is their ml model statement.

ml model d0 ZIP_FE_model (PAT = LOGR, nocons) if nonz > 0

I don't see any other obvious way of defining nonz for this part of the
program. Does anyone see any obvious problems?

You can find the code here [2] and inlined below.

Thanks for any help,

Skipper

[1] http://ideas.repec.org/p/dgr/kubcen/2011083.html
[2] https://gist.github.com/jseabold/6601357


--------------------------------------------------


set more off
capture program drop ZIP_FE_model

program define ZIP_FE_model
version 9.1

args todo b lnf
tempvar theta1 lambda last nonz w sln0 sln r0 r nb0 nb1 nb00 nb2 L2

local by "$MY_panel"
local byby "by `by'"
sort `by' year
local y "$ML_y1"

mleval `theta1' = `b'
di "`b'"

quietly {
    gen double `lambda' = exp(`theta1')

    `byby': gen double `last' = (_n == _N)
    `byby': egen double `nonz' = min(`y')
    `byby': egen double `w' = sum(`y')
    `byby': gen double `sln0' = lngamma(`y' + 1)
    `byby': egen double `sln' = sum(`sln0')
    `byby': gen double `r0' = `y'*ln(`lambda')
    `byby': egen double `r' = sum(`r0')
    `byby': egen double `nb0' = sum(`lambda')
    `byby': gen double `nb1' = `nb0'^`w'
    `byby': gen double `nb00' = `lambda'^`w'
    `byby': egen double `nb2' = sum(`nb00')

    `byby': gen double `L2' = lngamma(`w'+1) - `sln' + `r' - ln(`nb1' -
`nb2') if (`last' == 1 & `nonz'>0)
    di `L2'
    mlsum `lnf' = `L2' if (`last' == 1 & `nonz' > 0)

} /* end quietly */
end

/* Taken from http://cameron.econ.ucdavis.edu/mmabook/mmaprograms.html */
infile CUSIP ARDSSIC SCISECT LOGK SUMPAT LOGR70 LOGR71 LOGR72 LOGR73
 LOGR74 LOGR75 LOGR76 LOGR77 LOGR78 LOGR79 PAT70 PAT71 PAT72 PAT73 PAT74
PAT75 PAT76 PAT77 PAT78 PAT79 using
http://cameron.econ.ucdavis.edu/mmabook/patr7079.asc, clear
gen id = _n
label variable id "id"
reshape long PAT LOGR, i(id) j(year)
label variable PAT "Patents"

drop if year<75

xtpoisson PAT LOGR, fe i(id)

sort id year
gen nonz = 0
replace nonz = 1 if PAT > 0
/*sort id wave*/
global MY_panel id
ml model d0 ZIP_FE_model (PAT = LOGR, nocons) if nonz > 0
ml check
ml search
ml maximize, difficult
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index