Announcement

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

  • Plotting estimates from Lincom

    Dear Stata expert,

    ** Below i am including age as a continuous interaction term. outcome is anemia (binary), predictor is (black, binary)
    ** Below i get estimates for risk of anemia on a single age point.
    Qs:
    1- how to get estimates on age ranges, with intervals of 10 years.
    2- How to automatically capture all estimate points from below and plot it in a forestplot, either coefplot or other method, but not manually.
    3- Is it possible to get all odd ratios for all age points plotted in a line (same way as margin plots but for odd ratio)

    Code:
    webuse nhanes2, clear
    gen anemia = 0
    replace anemia =1 if hgb <=10
    logistic anemia female black##c.age
    prog myeret, eclass
      ereturn repost b=b V=V
    end
    matrix b = e(b)
    matrix V = e(V)
    lincom _b[1.black]+_b[1.black#c.age]*30, or
    lincom _b[1.black]+_b[1.black#c.age]*40, or
    lincom _b[1.black]+_b[1.black#c.age]*50, or
    lincom _b[1.black]+_b[1.blac#c.age]*60, or

    Help appreciated. Thanks

  • #2
    Question 1: I don't know what this means.

    Questions 2 and 3:
    Code:
    lincom _b[1.black]+_b[1.black#c.age]*30, or
    lincom _b[1.black]+_b[1.black#c.age]*40, or
    lincom _b[1.black]+_b[1.black#c.age]*50, or
    lincom _b[1.black]+_b[1.blac#c.age]*60, or
    
    frame create ors age or
    forvalues a = 30(10)60 {
        lincom _b[1.black] + _b[1.black#c.age]*`a'
        frame post ors (`a') (`r(estimate)')
    }
    
    frame change ors
    isid age, sort
    format or %3.2f
    list, noobs clean
    
    graph twoway connect or age, sort
    Note: As you do not state what version of Stata you are using, I am acting in accord with the Forum FAQ and assuming it is the current version, 16.0. If you are using an older version of Stata, this code will not work as frames are new in version 16. In that case, you can accomplish the same results by creating a -postfile- instead. -help postfile-

    Comment


    • #3
      My next thought, reading Clyde's post, is to also plot the confidence intervals. Using Nick Cox earlier post here on that subject, my code is:
      Code:
      * CI
      frame create orsCI age or orlb orub
      forvalues a = 30(10)60 {
          lincom _b[1.black] + _b[1.black#c.age]*`a'
          frame post orsCI (`a') (`r(estimate)') (`r(lb)') (`r(ub)')
      }
      
      frame change orsCI
      isid age, sort
      format or %3.2f
      format orlb %3.2f
      format orub %3.2f
      list, noobs clean
      
      graph twoway (connect or age , sort) (rcap orlb orub age)
      and this produces the following graph:

      Click image for larger version

Name:	GraphEstimatesFromLincomWithCI.png
Views:	1
Size:	17.2 KB
ID:	1529118
      http://publicationslist.org/eric.melse

      Comment

      Working...
      X