Announcement

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

  • Graph STATA RR 95% CI with different colors and space between bars

    Hello everybody,

    I am really struggling to create a graph in STATA that looks like the attached one with different colors and a space between the groups of bars (here cholesterol and diabetes) and a dashed line.

    It's my first time using STATA as a student. I was wondering if someone could help me?

    Thank you very much in advance for your help,

    JR
    Attached Files

  • #2
    Since you have 15 posts in this Forum, I gather you're aware that sharing "foreign" style documents is not the recommended approach.

    Please take a look at the FAQ and see how to share graphs in png extension.

    That said, the option - asyvars - provides different colors and - bargap() - will provide the gap between bars. You may start with - bargap(10) - and increase the number according to your taste.

    Hopefully that helps.
    Best regards,

    Marcos

    Comment


    • #3
      Thank you very much Marcos.

      OK I will know it for next time,

      Best regrads,

      JR

      Comment


      • #4
        Hi everyone,

        I have finally decided to use the following twoway command: twoway (rcap low95 high95 row, vert)(scatter zscore row if group =="ref", mcolor(red))(scatter zscore row if group =="path", mcolor(blue)),yline(0, lpattern(dash))

        to create the attached graph (not finished!)

        But I am still struggling to use different colors for the 95% ci. I'd like a blue ci bar for the ci bars associated with a blue dot and a red ci bar for the ci bars associated with the red plot.
        And also, I wanted to use a different gap between 2 consecutive bars larger than with the 2nd and the 3rd ones.

        Thanks a lot for your help,
        JR
        Attached Files

        Comment


        • #5
          But I am still struggling to use different colors for the 95% ci. I'd like a blue ci bar for the ci bars associated with a blue dot and a red ci bar for the ci bars associated with the red plot.
          Same logic that you employ for the scatter plots:

          Code:
          twoway (rcap low95 high95 row if group =="ref", lcolor(red) , vert) ///
          (rcap low95 high95 row if group =="path", lcolor(blue)) ///
          (scatter zscore row if group =="ref", mcolor(red)) ///
          (scatter zscore row if group =="path", mcolor(blue))

          And also, I wanted to use a different gap between 2 consecutive bars larger than with the 2nd and the 3rd ones.

          I have no idea what you mean by this. First, you do not have bars. But even if I replace bars with CIs, I still cannot follow.
          Last edited by Andrew Musau; 03 Sep 2020, 13:05.

          Comment


          • #6
            Thank you so much Andrew! It's been so helpful.

            For the gap question, I have actually 6 dots with their 95% CI. The first one on the x scale at 0.25, the second one at 0.5. Then the third one at 1 and the 4th at 1.25. I wanted a larger gap (a larger space) between the 2nd and the 3rd and a small gap between the 1st and the 2nd.

            Marcos said in his previous message that bargap() - can provide the gap between bars but it does not work with a twoway graph. I wanted to really choose the gap, the interval between the different 95%ci bars. Am I clearer?

            Thanks a lot!
            JR

            Comment


            • #7
              Just change the values of row and replace the x-axis labels with names of the pairs that you are plotting. If you struggle, copy and paste the result of

              Code:
              dataex low95 high95 zscore row group

              Comment


              • #8
                This is just to underline that my advice mainly relates to the information given in the first post, which mentioned the word "bars", hence I assumed it was a bar graph.
                Best regards,

                Marcos

                Comment


                • #9
                  I have not been clear enough Marcos, thank you all!

                  Best,
                  JR

                  Comment


                  • #10
                    No problem, Javier. It is clarified.
                    Best regards,

                    Marcos

                    Comment

                    Working...
                    X