Announcement

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

  • using margins to predict from 2 level categorical variable

    I have code a variable - categorical, which is called -severity- (excellent (1) - fair (2) - poor (3)) for a treatment variable (treatment = 1, treatment = 0 control)

    I am trying to plot onto a graphs to predict the probability of the person having excellent or fair or poor outcomes for treatment variables.
    However, I can't plot a line graph as the dependent variable is categorical, do you have any ideas how to plot the marginsplot graphs into 1 graph?

    Code:
    ologit severity treatment age gender [pw=weight]
    
    margins, at(treatment=(0/1)) predict(outcome(1)) atmeans ///excellent
    marginsplot
    
    margins, at(treatment=(0/1)) predict(outcome(2)) atmeans ///fair
    marginsplot
    
    margins, at(treatment=(0/1)) predict(outcome(3)) atmeans ///poor
    marginsplot
    
    ologit everity treatment age gender [pw=weight]
    predict probexcellent probfair probpoor 
    
    twoway (line probexcellent treatment, lcolour(dkgreen) lpattern(solid)) (line probfair treatment, lcolour(dknavy) lpattern(solid))










  • #2
    bar chart with 0/1 outcomes for each group?

    Comment


    • #3
      Thanks for this advice
      I've generated this graph (but they're 4 separate bar charts) is there a way how to combine them all on the same x axis into 1 graph (excellent - poor - fair) and instead label where '1' as: Excellent - Fair - Poor with a common y axis ( probability)

      If I'm not explaining myself well, I've edited the output in the desired picture.

      Code:
      ologit severity treatment age gender [pw=weight]
      
      margins, at(treatment=(0/1)) predict(outcome(1)) atmeans ///excellent
      marginsplot, plot(treatment) recast(bar) allxlabels by(treatment) name(m1, replace)
      
      margins, at(treatment=(0/1)) predict(outcome(2)) atmeans ///fair
      marginsplot, plot(treatment) recast(bar) allxlabels by(treatment) name(m2, replace)
      
      
      margins, at(treatment=(0/1)) predict(outcome(3)) atmeans ///poor
      marginsplot, plot(treatment) recast(bar) allxlabels by(treatment) name(m3, replace)
      
      graph combine m1 m2 m3, ycommon name(g2, replace)





      Attached Files
      Last edited by Martin Imelda Borg; 17 Jan 2024, 09:05. Reason: code update

      Comment


      • #4
        Not ideal, but a start:
        Code:
        margins, at(treatment=(0/1)) predict(outcome(1)) predict(outcome(2)) predict(outcome(3)) atmeans 
        marginsplot

        Comment


        • #5
          thanks for trying, but using that code - stata returns the error::

          ) required

          Comment


          • #6
            That's weird. I'm not sure why that is happening. The following, with the exact same code, works for me in Stata 16.1.
            Code:
            webuse nhanes2f, clear
            ologit health i.female age c.age#c.age [pw=finalwgt]
            margins , at(female=(0/1)) predict(outcome(1)) predict(outcome(2)) predict(outcome(3)) predict(outcome(4)) atmeans 
            marginsplot,

            Comment

            Working...
            X