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

# st: Bivariate Negative Binomial using -ml-

 From Tirthankar Chakravarty To statalist@hsphsun2.harvard.edu Subject st: Bivariate Negative Binomial using -ml- Date Fri, 13 Mar 2009 01:47:22 +0000

```Hello,

I am trying to implement a bivariate negative binomial regression
model as reported on pg. 212 of Rainer Winkelmann's book "Econometric
Analysis of Count Data" (Springer 5th edition 2008).

For those who do not have access to the book, it is the same
likelihood per observation reported in his paper ("Seemingly Unrelated
Negative Binomial Regression", Oxford Bulletin of Economics and
Statistics, Vol. 62, Issue 4, pg. 553-560, 2000) in equation (2)
substituting the NB-I density for the Poisson (also see equation (6)).

I have been trying to implement it using -ml- and my code is as below.
The problem is that -ml search- fails to find feasible initial values.
As -ml search- suggests, this may be because my code is "broken". I
have been looking at it but cannot spot the problem. Any help
debugging will be greatly appreciated.

Thanks and best regards,

Tirthankar

####################### BEGIN CODE################################
*********************
** Multivariate Negative Binomial (Ch. 7 pg.212, Winkelmann 2008) using -ml-
*********************
cap program drop binbreg2
program define binbreg2
version 9.1
args lnf xb1 xb2 sigma loggamma

tempvar z1 z2 mu1 mu2 fnb1 fnb2 fnb suma
qui gen double `mu1' = exp(`xb1')
qui gen double `mu2' = exp(`xb2')
local s = min(\$ML_y1, \$ML_y2)
qui gen double `suma' = 0
qui gen float `z1' = .
qui gen float `z2' = .
qui gen float `fnb1' = .
qui gen float `fnb2' = .
qui gen float `fnb' = .
forvalues i = 0/`s' {
qui replace  `z1' = \$ML_y1 - `i'
qui replace  `z2' = \$ML_y2 - `i'
qui replace  `fnb1' = lngamma(`mu1'/`sigma' +
`z1')-lngamma(`mu1'/`sigma') - lngamma(`z1' + 1) ///
-(`mu1'/`sigma')*log(1 + `sigma') +
`z1'*log(`sigma'/(1+`sigma'))
qui replace  `fnb2' = lngamma(`mu2'/`sigma' +
`z2')-lngamma(`mu2'/`sigma') - lngamma(`z2' + 1) ///
-(`mu2'/`sigma')*log(1 + `sigma') +
`z2'*log(`sigma'/(1+`sigma'))
qui replace  `fnb' = lngamma(`loggamma'/`sigma' +
`i')-lngamma(`loggamma'/`sigma') - lngamma(`i' + 1) ///
-(`loggamma'/`sigma')*log(1 + `sigma') +
`i'*log(`sigma'/(1+`sigma'))
qui replace `suma' = `suma' + `fnb1' + `fnb2' + `fnb'
}
qui replace `lnf' = `suma' if `suma' !=0 // Tried different
versions of this.
// qui replace `lnf' = . if `suma' ==0
end
ml model lf binbreg2 (first: breadth = sizeband lnemp lnturnover
geo_national geo_europe geo_other prodinnov dturnover_std
dturnover_std_sq) ///
(second: depth= sizeband lnemp lnturnover geo_national geo_europe
geo_other prodinnov dturnover_std dturnover_std_sq) /lna /loggamma
ml check
ml max
####################### END CODE################################

--
To every ω-consistent recursive class κ of formulae there correspond
recursive class signs r, such that neither v Gen r nor Neg(v Gen r)
belongs to Flg(κ) (where v is the free variable of r).

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```

 © Copyright 1996–2021 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index