Announcement

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

  • Creating a forest plot with odds ratios

    Hello I would like to create a forest plots for the odds ratios of the depedent variable on the outcome.
    I have 5 models.

    I have tried
    Code:
    //Mi  - model 1
    quietly logit mi_30 asa [pw=_weight], or if procedure == 0
    //stroke - model 2
    queitly logit stroke_30 asa [pw=_weight], or if procedure == 0
    // If function is not allowed

    The plan was then to use -coef-plot

    Code:
    coefplot, drop(˙cons) xline(1) eform xtitle(Odds ratio)
    I only wanted to show the outcomes of mi_30 and stroke_30 for procedure == 0 and procedure ==1 on the coef plot.
    However, the -coef- will plot all the OR of all the predictors inlcuding ASA - which is not what I want

    Is there an alternative?

  • #2
    coefplot is from SSC, as you are asked to explain (FAQ Advice #12).


    EDITED:

    I only wanted to show the outcomes of mi_30 and stroke_30 for procedure == 0 and procedure ==1 on the coef plot.
    What do you mean by this? These are your outcomes. You can only plot estimated coefficients.
    Last edited by Andrew Musau; 17 Oct 2023, 09:04.

    Comment


    • #3
      With regards to -if- function I was following the advice of:
      https://www.stata.com/meeting/german.../de14_jann.pdf
      slide 21


      just wanted to plot the odds ratios of my procedure 0 and procedure 1 just to graphically depict the outcome

      Comment


      • #4
        In the link, the coefficients on the regressors are plotted. "foreign" is just a grouping variable.

        Comment


        • #5
          Returning first to your parallel thread, https://www.statalist.org/forums/for...or-odds-ratios:

          It is somewhat misleading to claim that the command:
          Code:
          regress price mpg trunk length turn if foreign==0
          ... is the source for the plot that you show. From your link, the full sequence of commands run is as follows:
          Code:
          regress price mpg trunk length turn if foreign==0
          estimates store D
          regress price mpg trunk length turn if foreign==1
          estimates store F
          That is, two different regressions are run: one for "foreign" and one for "domestic". Their respective results are stored, and then displayed simultaneously on a single plot.

          You are correct in your original assertion that "one can not present the OR of both base-level and value 1". Specifically, an OR is an odds ratio: in this case, the ratio of level 1 to level 0. There is no such thing as an OR for level 0 or level 1 alone (that would be an "odds", and would require a quite different interpretation).

          Now, you say "Hello I would like to create a forest plots for the odds ratios of the dependent variable on the outcome" ... and then "I only wanted to show the outcomes of mi_30 and stroke_30 for procedure == 0 and procedure ==1 on the coef plot".
          It is not clear what your dependent variable is; if it is not ASA (as you state), then presumably it is "procedure 0 vs 1". But you cannot have "procedure" as your dependent variable and then fit separate models for procedure==0 and procedure==1 (i.e. the grouping variable). That does not make sense. To return to the "regress" example: price is the outcome; mpg, trunk, length and turn are all dependent variables, and foreign is the grouping variable. You are currently seeking to have procedure do two jobs at once. (That is, for example, the jobs of both mpg and foreign in the "regress" example.)

          Comment


          • #6
            David Fisher Thank you for pointing this out

            I've managed to figure this out after some time (using sample dataset below), by using the following code

            Code:
            logit mi_30 treatment price, or
            est store m1
            logit uti treatment price, or
            est store m2
            
            coefplot m1 m2, sort nolabel drop(_cons) keep(*treatment)  //keep - to keep only OR for treatment for each outcome
            I obtain the following plot:
            Click image for larger version

Name:	Screenshot 2023-10-18 at 19.17.47.png
Views:	1
Size:	377.7 KB
ID:	1730754




            However my question is: As I am going to have around 5 models, this may make it a bit complex for the reader, with 5 different colours.
            Is there another alternative solution to perhaps try present the plot in this manner - I've tweaked the plot myself, not sure if this is possible however.
            Really appreciate your expertise and time !
            Click image for larger version

Name:	Screenshot 2023-10-18 at 19.15.46.png
Views:	1
Size:	92.8 KB
ID:	1730755









            Code:
            * Example generated by -dataex-. For more info, type help dataex
            clear
            input str18 make int price float gear_ratio byte foreign float(treatment mi_30 uti) byte(_est_m1 _est_m2)
            "AMC Concord" 4099 3.58 0 1 1 1 1 1
            "AMC Pacer" 4749 2.53 0 0 1 0 1 1
            "AMC Spirit" 3799 3.08 0 0 0 0 1 1
            "Buick Century" 4816 2.93 0 0 0 1 1 1
            "Buick Electra" 7827 2.41 0 1 1 0 1 1
            "Buick LeSabre" 5788 2.73 0 0 1 1 1 1
            "Buick Opel" 4453 2.87 0 0 1 0 1 1
            "Buick Regal" 5189 2.93 0 0 1 1 1 1
            "Buick Riviera" 10372 2.93 0 1 1 1 1 1
            "Buick Skylark" 4082 3.08 0 0 0 1 1 1
            "Cad. Deville" 11385 2.28 0 1 1 0 1 1
            "Cad. Eldorado" 14500 2.19 0 0 0 1 1 1
            "Cad. Seville" 15906 2.24 0 1 1 1 1 1
            "Chev. Chevette" 3299 2.93 0 1 0 0 1 1
            "Chev. Impala" 5705 2.56 0 0 0 0 1 1
            "Chev. Malibu" 4504 2.73 0 0 0 . 1 0
            "Chev. Monte Carlo" 5104 2.73 0 0 0 0 1 1
            "Chev. Monza" 3667 2.73 0 1 1 0 1 1
            "Chev. Nova" 3955 2.56 0 0 1 1 1 1
            "Dodge Colt" 3984 3.54 0 1 0 0 1 1
            end
            label values foreign origin
            label def or

            Comment


            • #7
              Hi Tara,

              Further down the page of https://repec.sowi.unibe.ch/stata/co...g-started.html is an example of the "bycoefs" option, which I think is what you need?

              Code:
              clear
              input str18 make int price float gear_ratio byte foreign float(treatment mi_30 uti) byte(_est_m1 _est_m2)
              "AMC Concord" 4099 3.58 0 1 1 1 1 1
              "AMC Pacer" 4749 2.53 0 0 1 0 1 1
              "AMC Spirit" 3799 3.08 0 0 0 0 1 1
              "Buick Century" 4816 2.93 0 0 0 1 1 1
              "Buick Electra" 7827 2.41 0 1 1 0 1 1
              "Buick LeSabre" 5788 2.73 0 0 1 1 1 1
              "Buick Opel" 4453 2.87 0 0 1 0 1 1
              "Buick Regal" 5189 2.93 0 0 1 1 1 1
              "Buick Riviera" 10372 2.93 0 1 1 1 1 1
              "Buick Skylark" 4082 3.08 0 0 0 1 1 1
              "Cad. Deville" 11385 2.28 0 1 1 0 1 1
              "Cad. Eldorado" 14500 2.19 0 0 0 1 1 1
              "Cad. Seville" 15906 2.24 0 1 1 1 1 1
              "Chev. Chevette" 3299 2.93 0 1 0 0 1 1
              "Chev. Impala" 5705 2.56 0 0 0 0 1 1
              "Chev. Malibu" 4504 2.73 0 0 0 . 1 0
              "Chev. Monte Carlo" 5104 2.73 0 0 0 0 1 1
              "Chev. Monza" 3667 2.73 0 1 1 0 1 1
              "Chev. Nova" 3955 2.56 0 0 1 1 1 1
              "Dodge Colt" 3984 3.54 0 1 0 0 1 1
              end
              
              set seed 1
              
              gen byte outcome1 = round(uniform())
              gen byte outcome2 = round(uniform())
              gen byte outcome3 = round(uniform())
              
              logistic outcome1 treatment price
              estimates store outcome1
              logistic outcome2 treatment price
              estimates store outcome2
              logistic outcome3 treatment price
              estimates store outcome3
              
              coefplot outcome1 || outcome2 || outcome3, drop(_cons price) bycoefs xtitle(Odds ratio of treatment) xlabel(-.693 "0.5" 0 "1" .693 "2" 1.386 "4")
              Click image for larger version

Name:	Graph.png
Views:	1
Size:	36.2 KB
ID:	1730786

              Comment


              • #8
                Thanks, just downloaded schemepacks. Graph looks great.

                An additional question, is there a way I can rename the 'outcome1', I tried

                Code:
                coeflabels(outcome1="Myocardial Infarction")
                However this didn't work, I suppose as this is for coefvariables
                I then tried the shortcut to rename my models as the variables I want to see in graph.

                I managed to get away with most variables renamed by storing the models as -estimates store MI-

                The only limitation is that a model name such as : VTE&PE is not accepted by stata

                Question 1:
                Do you have any suggesstions?

                Question 2:
                Do you have an idea if I can add the p-values; at outcome1 or is the only alternative to add as notes?
                Last edited by Tara Boyle; 20 Oct 2023, 13:34.

                Comment

                Working...
                X