Announcement

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

  • Graph with Y axis as string

    Hi everyone,

    I have data like below: 25 different methods that generate 25 different estiamtion on OR and its 95%CI. I want to generate a plot with the axis as the methods' name so that people can see the results related to the name of the methods (This can be easily done In excel). How can I do it in stata?

    Code:
    __method __or_ __lci_or_ __uci_or_
    A .6492 .258189 1.63237
    B .682846 .133547 3.49148
    C .6492 .10206 4.12953
    D .586633 .299436 1.14929
    E .594977 .303478 1.16647
    F .342782 .134567 .873165
    G .119268 .012092 1.17643
    H .342782 .016632 7.06464
    I .660587 .209265 2.08528
    J .660587 .209265 2.08528
    K .660587 .209265 2.08528
    L .778194 .325669 1.85951
    M .711595 .193472 2.61727
    N .778194 .185898 3.25763
    O .790423 .437463 1.42816
    P .018483 .001191 .286725
    Q .587435 .298901 1.15449
    R .783607 .432965 1.41822
    S .601916 .306494 1.18209
    T .165793 .012218 2.24971
    U .280154 .017255 4.54869
    V .790423 .437463 1.42816
    W .751405 .499381 1.13062
    X .757768 .477562 1.20238
    Y .880356 .200964 3.85654
    Thanks
    Chang

  • #2
    A basic one.

    Code:
    graph hbar (asis) or, over(method)

    Comment


    • #3
      I fear that pointing you to graph hbar is a distraction as you will want to show the confidence intervals too.

      Also, I imagine that A to Y are just coy labels and that you should prefer a meaningful order to testing whether readers understand the alphabet in question.

      Here is one approach using myaxis from the Stata Journal. https://www.stata-journal.com/articl...article=st0654 leads to a freely available pdf. See also if you wish

      https://www.statalist.org/forums/for...e-or-graph-use

      Code:
      clear 
      
      input str1 __method __or_ __lci_or_ __uci_or_
      A .6492 .258189 1.63237
      B .682846 .133547 3.49148
      C .6492 .10206 4.12953
      D .586633 .299436 1.14929
      E .594977 .303478 1.16647
      F .342782 .134567 .873165
      G .119268 .012092 1.17643
      H .342782 .016632 7.06464
      I .660587 .209265 2.08528
      J .660587 .209265 2.08528
      K .660587 .209265 2.08528
      L .778194 .325669 1.85951
      M .711595 .193472 2.61727
      N .778194 .185898 3.25763
      O .790423 .437463 1.42816
      P .018483 .001191 .286725
      Q .587435 .298901 1.15449
      R .783607 .432965 1.41822
      S .601916 .306494 1.18209
      T .165793 .012218 2.24971
      U .280154 .017255 4.54869
      V .790423 .437463 1.42816
      W .751405 .499381 1.13062
      X .757768 .477562 1.20238
      Y .880356 .200964 3.85654
      end 
      
      myaxis toshow = __method, sort(mean __or_)
      set scheme s1color  
      scatter toshow __or_, yla(1/25, ang(h) valuelabel noticks) || rcap __lci_or_ __uci_or_ toshow, horizontal legend(off) ytitle(method) xtitle(odds ratio and CI)
      Click image for larger version

Name:	oddsratio.png
Views:	1
Size:	30.3 KB
ID:	1633973


      Comment


      • #4
        Note that if you really need alphabetical order, it yields to essentially the same method:

        Code:
        gen order = -_n
        myaxis badchoice=__method, sort(mean order)
        scatter badchoice __or_, yla(1/25, ang(h) valuelabel noticks) || rcap __lci_or_ __uci_or_ badchoice, horizontal legend(off) ytitle(method) xtitle(odds ratio and CI)

        Comment


        • #5
          Since these are odds ratios the graph often becomes easier to read with a log scale:

          Code:
          scatter toshow __or_, yla(1/25, ang(h) valuelabel noticks) || ///
                  rcap __lci_or_ __uci_or_ toshow, horizontal legend(off) ///
                  ytitle(method) xtitle("odds ratio and CI (log scale)")  ///
                  xscale(log) xlab(0.001 0.01 0.1 1 10) xline(1)
          ---------------------------------
          Maarten L. Buis
          University of Konstanz
          Department of history and sociology
          box 40
          78457 Konstanz
          Germany
          http://www.maartenbuis.nl
          ---------------------------------

          Comment


          • #6
            Thanks everyone, it works well!

            Comment

            Working...
            X