Announcement

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

  • plotting confidence intervals in stata

    Dear All,
    i have risk ratios for a disease with their confidence intervals by age group and i am plotting these by 3 levels of exposure variable. which is the simplest way to plot the confidence intervals in stata? thanks

  • #2
    With official Stata commands you can do it by plotting the means with -graph twoway scatter- and the confidence intervals with -graph twoway rcap-, all superimposed. There is also a user-written command -ciplot- available from SSC. I have no experience with -ciplot- myself, so I can't advise whether it is an improvement over doing it with official Stata commands.

    Comment


    • #3
      The help for ciplot advises:

      (note added August 2011)

      For fuller flexibility, consider using statsby first and then standard graphics commands (Cox 2010).

      [...]

      Cox, N.J. 2010. Speaking Stata: The statsby strategy. Stata Journal 10: 143-151.


      Comment


      • #4
        Thanks a lot Clyde and Nick for the fast response. an example of data i want to plot are shown below. it appears that ciplot computes its own rates or means and confidence intervals. it doesn't seem to plot already computed CIs.
        agegrp RR Lower higher
        18-20 1 0.81 8.56
        21-25 2.63 0.82 8.45
        26-30 2.64 0.88 9.37
        31-35 2.87 0.97 10.30
        36-40 3.16 0.83 9.80
        41-45 2.86 1.65 17.24
        46-50 5.33 0.96 11.55
        51-55 3.33 0.38 7.92
        56-60 1.74 1.33 16.66
        61-65 4.71 1.27 18.52
        66-70 4.85 0.03 0.22

        Comment


        • #5
          First, there is something wrong with the numbers in your example data: in the final observation, the confidence interval does not contain the value of rr.

          You have another problem: you need a variable for your horizontal axis. At the moment you have an agegrp variable which is a range, represented as a string. You need to convert that to a single number for graphing. In the code below, I do that by using the midpoint of each age group.

          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input str5 agegrp float(rr lower higher)
          "18-20"    1  .81  8.56
          "21-25" 2.63  .82  8.45
          "26-30" 2.64  .88  9.37
          "31-35" 2.87  .97  10.3
          "36-40" 3.16  .83   9.8
          "41-45" 2.86 1.65 17.24
          "46-50" 5.33  .96 11.55
          "51-55" 3.33  .38  7.92
          "56-60" 1.74 1.33 16.66
          "61-65" 4.71 1.27 18.52
          "66-70" 4.85  .03   .22
          end
          
          split agegrp, parse("-") gen(age) destring
          gen age = (age1+age2)/2
          
          graph twoway (scatter rr age) (rcap lower higher age)
          In the future, when showing data examples, please use the -dataex- command to do so, as I have here. If you are running version 15.1 or a fully updated version 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.



          When asking for help with code, always show example data. When showing example data, always use -dataex-.

          Comment

          Working...
          X