I'm trying to replicate a Bayesian model similar to one found on page 47-51 of this file (https://www.stata.com/meeting/chicag...go16_balov.pdf).
Code:
use http://www.stata-press.com/data/r15/usmacro
mswitch dr fedfunds
generate id=_n
help fvset
fvset base none id
set seed 12345
bayesmh fedfunds = (({state:}==1)*{mu1}+({state:}==2)*{mu2}), ///
likelihood(normal({sig2})) redefine(state:i.id) ///
prior({state:}, index({p1}, (1-{p1}))) ///
prior({p1}, uniform(0, 1)) ///
prior({mu1} {mu2}, normal(0, 100)) ///
prior({sig2}, igamma(0.1, 0.1)) ///
init({p1} 0.5 {mu1} 1 {mu2} 1 {sig2} 1 {state:} 1) ///
block({sig2}, gibbs) block({p1}) block({mu1}{mu2}) ///
exclude({state:}) dotsHowever, when I attempted to copy & paste the code given above in the example to Stata but it keeps returning this error
Code:
. bayesmh fedfunds = (({state:}==1)*{mu1}+({state:}==2)*{mu2}), ///
invalid bayesmh specification
To fit one of the supported models, you must specify a likelihood model in option likelihood() and a prior distribution in option prior(). To fit your own
model, you must specify, for example, the name of your posterior-function evaluator in option evaluator(). See bayesmh and bayesmh evaluators for details.
r(198);Code:
mswitch dr fedfunds
matrix list e(b)
e(b)[1,5]
State1: State2: lnsigma: p11: p21:
_cons _cons _cons _cons _cons
y1 3.70877 9.5567934 .74553174 -4.0045427 2.9369133
#store the results in a matrix for further extraction
matrix b = e(b)
#extract and assign them accordingly to a variable
gen mu1=b[1,1]
gen mu2=b[1,2]
gen sig1=b[1,3]
gen sig2=b[1,4]
gen p1=b[1,5]I would really appreciate it if you guys can point out my mistakes and help me replicate the example above, and kindly help me with these 3 questions:
- What do the state: as in this code mean?
Code:
bayesmh fedfunds = (({state:}==1)*{mu1}+({state:}==2)*{mu2}), - As the 2 states follow First-Order Markov Chain (so that we need transition probabilities p11 and p22 for both state), why does the example have only 1 probability variable p1, when it should have 2?
- Assuming that I replicate and run the Bayesian model successfully, how I can extract the data of p11 and p22 to graph a chart similar to this one?
I'm aware that this is a very simple example, just that I'm a beginner to Stata, I would appreciate any help I can get! I'm using Stata15.
Best,
0 Response to [Beginner question] Bayesian Hierarchical Model
Post a Comment