Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Specifying autoregressive errors with Bayesmh

    Hello Statlisters,

    Can anyone tell me whether it is possible to specify first-order autoregressive errors using Bayesmh? Specifically, I'm wondering if my code below can be extended to specify the following structure to the error terms.

    Click image for larger version

Name:	autoregressive structure.jpg
Views:	3
Size:	7.8 KB
ID:	1412356

    fvset base none id
    bayesmh y1 y2 = i.id x ///
    , noconstant likelihood(mvnormal({S, matrix})) ///
    /// variance matrix priors and blocks ///
    prior({S,matrix}, iwishart(2,1000,I(2))) block({S,matrix}) ///
    /// y1 priors and blocks ///
    prior({y1: x}, normal(0,1000)) ///
    block({y1: x}) ///
    prior({y1: i.id}, normal({y1: _cons},{Sigma1})) block({y1: i.id}, reffects) ///
    prior({Sigma1}, igamma(.001,.001)) block({Sigma1}, gibbs) ///
    prior({y1: _cons}, normal(0,1000)) block({y1: _cons}, gibbs) ///
    ///
    ///y2 priors and blocks ///
    prior({y2: x}, normal(0,1000)) ///
    block({y2: x}) ///
    prior({y2: i.id}, normal({y2: _cons},{Sigma2})) block({y2: i.id}, reffects) ///
    prior({Sigma2}, igamma(.001,.001)) block({Sigma2}, gibbs) ///
    prior({y2: _cons}, normal(0,1000)) block({y2: _cons}, gibbs) ///
    burnin(2000) dots mcmcs(10000) rseed(12345) ///
    exclude({y1: i.id} {y2: i.id})

    Any insights you could provide would be greatly appreciated.

    Justin

  • #2
    Hi Justin,

    I believe that, with a bit of more work, your first-order autoregressive model can be simulated with bayesmh. I suggest, instead of using the regression specification
    Code:
    y1 y2 = i.id x
    to apply a nonlinear equation specification using expressions
    Code:
    (y1 = ... + {rho1}*(L1.y1-...))
    (y2 = ... + {rho2}*(L1.y2-...))
    where you replace ... with the xb components of your equations.

    Below I show you a simplified model without random-effects in order to make the specification more clear.
    Code:
     bayesmh (y1 = ({cons1}+{beta1}*x+{rho1}*(L1.y1-{cons1}-{beta1}*L1.x)))  ///
             (y2 = ({cons2}+{beta2}*x+{rho2}*(L1.y2-{cons2}-{beta2}*L1.x))), ///
        likelihood(mvnormal({Sigma,matrix}))                                 ///
        prior({rho1}{rho2}, uniform(-1,1))                                   ///
        prior({beta1}{cons1}{beta2}{cons2}, normal(0, 100))                  ///
        prior({Sigma,matrix}, iwishart(2, 10, I(2)))                         ///
        block({Sigma,matrix}, gibbs) block({rho1}) block({rho2}) dots
    After verifying that this model formulation is correct, you may replace the parameters {cons1} and {cons2} with some random effects.

    Nikolay

    Comment


    • #3
      Fantastic! Thank you, Nikolay! This solution seriously just made my week. Having access to experts like you who are so willing to assist is among the many reasons that Stata is the best.

      Comment


      • #4
        Hello Mr. Nikolay Balov (StataCorp)

        We have a problem with using "bayesmh" to estimate the threshold of a certain variable. We get an "r(503);" error when we run the following code. My colleague also tried this command on another PC and got the same issue.
        Code:
        .bayesmh rgdp = (cond(L1.rgdp<{r},{r1:a0}+{r1:a1}*L1.rgdp,{r2:a0}+{r2:a1}*L1.rgdp)),likelihood(normal(cond(L1.rgdp<{r}, {sig1}, {sig2})))prior({r1:}, normal(0, 100)) block({r1:})prior({r
        > 2:}, normal(0, 100)) block({r2:})prior({sig1}, igamma(0.01, 0.01)) block({sig1})prior({sig2}, igamma(0.01, 0.01)) block({sig2})prior({r}, uniform(-0.5, 0.5)) block({r})rseed(17) init({s
        > ig1} {sig2} 1) dots
        We get the following error:
        Burn-in 2500 normal: 297 found where 296 rows expected
        r(503);
        ###################################
        Also, we get another error when we run the following command

        Code:
         bayesmh rgdp = (cond(L1.rgdp<{r},{r1:a0}+{r1:a1}*L1.rgdp,{r2:a0}+{r2:a1}*L1.rgdp)),likelihood(normal(cond(L1.rgdp<{r}, {sig1}, {sig2})))prior({r1:}, normal(0, 100)) block({r1:})prior({r
        > 2:}, normal(0, 100)) block({r2:})prior({sig1}, igamma(0.01, 0.01)) block({sig1})prior({sig2}, igamma(0.01, 0.01)) block({sig2})prior({r}, uniform(-0.5, 0.5)) block({r})rseed(17) init({s
        > ig1} {sig2} 1) dots
        We get the following error
        Burn-in ...
        normal: invalid parameters
        r(503);

        May you please help us with this issue?
        Last edited by Sarah Magd; 11 Nov 2022, 04:36.

        Comment

        Working...
        X