Announcement

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

  • Extracting coefficient from matrix after bayes command

    Can anyone please suggest how I can extract the coefficient of my explanatory variable after using the Bayes command? Example below

    Code:
    sysuse auto, clear
    bayesmh foreign trunk mpg, likelihood(logit) prior({foreign:}, normal(0,1000))
    
    mat list e(mean)
    result of mat list
    Code:
    e(mean)[1,3]
    trunk    mpg    _cons
    Mean  -.13484497    .11758344    -1.7574044
    I want to extract mean of trunk and mpg only in a postfile but not sure how to define the matrix for each of the explanatory variables.

    My try shows an error message:
    Code:
    postfile examp trunk using "bay.dta", replace
    bayesmh foreign trunk mpg, likelihood(logit) prior({foreign:}, normal(0,1000))
    post examp (e(mean))
    postclose examp
    type mismatch
    post: above message corresponds to expression 1, variable means
    r(109);

    any suggestion is appreciated
    Last edited by Madu Abuchi; 23 Feb 2019, 03:13.

  • #2
    post expect expressions representing single values, not a matrix. Refer to the elements you want to save:
    Code:
    post examp (el(e(mean),1,1))  (el(e(mean),1,2))
    or
    Code:
    tempname trunk
    tempname mpg
    
    scalar `trunk' = el(e(mean),1,1)
    scalar `mpg' = el(e(mean),1,2)  
    
    post examp (`trunk') (`mpg')

    Comment

    Working...
    X