Announcement

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

  • how to specify likewood and prior evaluators in a Bayesian linear hierarchical model

    hello everyone, I'm new to bayesian linear hierarchical analysis. But every time I enter the stata command, I get the following error code as a screenshot
    HTML Code:
    bayesmh pauvretelecture = b0 + b1*x1 + b2*x2 + b3*x3 + b4*x4 + b5*x5 + b6*x6 + ///
        u_school + u_class, ///
        likelihood(normal(_mean, sigma2)) ///
        prior({b0 b1 b2 b3 b4 b5 b6}, normal(0, 100)) ///
        prior({sigma2}, igamma(0.01, 0.01)) ///
        prior({u_school}, normal(0, tau_school)) ///
        prior({u_class}, normal(0, tau_class)) ///
        prior({tau_school tau_class}, igamma(0.01, 0.01)) ///
        block({b0 b1 b2 b3 b4 b5 b6 sigma2}) ///
        block({u_school tau_school}) ///
        block({u_class tau_class})
    HTML Code:
    program my_llevaluator
        version 17.0
        args lnf b0_elect b1_elect b2_elect b0_math b1_math b2_math sigma2_elect sigma2_math
    
        // Utiliser les variables locales pour représenter les données et les prédicteurs
        tempvar xb_elect xb_math resid_elect resid_math
    
        // Calculer la combinaison linéaire pour chaque équation
        quietly {
            generate double `xb_elect' = `b0_elect' + `b1_elect' * x1 + `b2_elect' * x2
            generate double `xb_math' = `b0_math' + `b1_math' * x1 + `b2_math' * x2
    
            // Calculer les résidus
            generate double `resid_elect' = pauvretelect - `xb_elect'
            generate double `resid_math' = pauvretemath - `xb_math'
    
            // Calculer la log-vraisemblance
            generate double `lnf' = ln(normalden(`resid_elect', 0, sqrt(`sigma2_elect'))) + ///
                                    ln(normalden(`resid_math', 0, sqrt(`sigma2_math')))
        }
    end
    I've tried several code snippets to specify the evaluators but to no avail
    Click image for larger version

Name:	test bayes 1.png
Views:	1
Size:	57.7 KB
ID:	1764625

  • #2
    Rather than going into it here, I recommend taking Stata's error message's admonition to heart, namely, "See . . . . bayesmh evaluators for details." That help file (and corresponding user's manual entry) shows how to specify user-written log-likelihood programs, including multiple-equation models, as well as those whose multiple equations involve common predictors.

    More to the point: why aren't you using something like
    Code:
    bayes: mvreg
    for your particular case?

    Comment

    Working...
    X