Dear all,
I am trying to investigate an empirical problem that requires estimation of Bayesian Poisson regression with random parameters.
I am aware that Poisson distribution is one of the many built-in likelihoods that comes built-in Stata's bayesmh command.
As such, I tried the following:
My understanding is that bayesmh likelihood option can be slow for complex problems. Am i right? Perhaps, that's why Stata has taken almost two hours before even starting the burn-in iterations.
With this said, i thought that using bayesmh "llevaluator" option can be faster. Below is the user-defined Poisson likelihood which is then called by bayesmh llevaluator option.
When i run this, Stata returns the following error:
"ml model not found" and "wal_poiss could not be evaluated."
I am certain that i am missing an important attribute of the log-likelihood evaluator in the lleval option in above code.
Can someone please guide me in this regard?
Any help is highly appreciated!
-Behram
I am trying to investigate an empirical problem that requires estimation of Bayesian Poisson regression with random parameters.
I am aware that Poisson distribution is one of the many built-in likelihoods that comes built-in Stata's bayesmh command.
As such, I tried the following:
Code:
sysuse auto //Example
gen id = _n //id created just for the sake of demonstration
//Bayesian Random Coefficients Poisson using bayesmh "likelihood" option
set seed 123
bayesmh trunk i.id#c.weight i.id#c.price, likelihood(poisson) ///
prior({trunk:i.id#c.weight},normal({trunk:weight},{Sigma1}))
prior({trunk:i.id#c.price},normal({trunk:price},{Sigma2}))
prior({trunk: _cons weight price}, normal (0,100)) ///
prior({Sigma1}, igamma(0.001, 0.001)) ///
prior({Sigma2}, igamma(0.001, 0.001)) ///
block({Sigma1}, gibbs) ///
block({Sigma2}, gibbs) ///
block({trunk:i.id#c.weight}) ///
block({trunk:i.id#c.price}) /// ///
exclude({trunk:i.id#c.weight}{trunk:i.id#c.price}) dots
bayesstats ic
With this said, i thought that using bayesmh "llevaluator" option can be faster. Below is the user-defined Poisson likelihood which is then called by bayesmh llevaluator option.
Code:
//User Defined Poisson Likelihood
program drop wal_poiss
program define wal_poiss
version 14.2
args todo b lnf
tempvar theta1
mleval `theta1' = `b', eq(1)
local y "$ML_y1"
tempvar lnyfact mu
quietly gen double `lnyfact' = lnfactorial(`y')
quietly gen double `mu' = exp(`theta1')
mlsum `lnf' = -`mu' + `y'*ln(`mu') - `lnyfact'
end
ml check
//ml model trunk weight price
//ml maximize
//Bayesian Random Coefficients Poisson using bayesmh "lleval" option
set seed 123
bayesmh trunk i.id#c.weight i.id#c.price, lleval(wal_poiss) /// I suspect am missing important attribute of the log-likelihood evaluator in the lleval option
prior({trunk:i.id#c.weight},normal({trunk:weight},{Sigma1})) ///
prior({trunk:i.id#c.price},normal({trunk:price},{Sigma2})) ///
prior({trunk: _cons weight price}, normal (0,100)) ///
prior({Sigma1}, igamma(0.001, 0.001)) ///
prior({Sigma2}, igamma(0.001, 0.001)) ///
block({Sigma1}, gibbs) ///
block({Sigma2}, gibbs) ///
block({trunk:i.id#c.weight}) ///
block({trunk:i.id#c.price}) /// ///
exclude({trunk:i.id#c.weight}{trunk:i.id#c.price}) dots
bayesstats ic
"ml model not found" and "wal_poiss could not be evaluated."
I am certain that i am missing an important attribute of the log-likelihood evaluator in the lleval option in above code.
Can someone please guide me in this regard?
Any help is highly appreciated!
-Behram

Comment