Announcement

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

  • How to generate 2 yaxis graph with 2 xaxis group with SD?

    I have the information here, on the table
    weeks ISpre A1M B2M sdis sdam sdbm group hiISpre loISpre hiB2M loBM hiA1M loA1M
    1 4 2 46 3 1 11 2 5 2 53 39 3 1
    2 3 3 41 2 1 9 2 5 2 46 35 3 2
    3 2 2 42 2 1 8 2 3 1 47 37 3 2
    1 4 3 50 3 1 16 1 5 2 60 40 4 3
    2 2 3 42 1 1 9 1 3 2 48 36 3 2
    3 3 2 41 1 1 10 1 4 2 47 35 3 2
    I want to made graph in the figure
    I use command
    ** graph bar b2m A1M ISpre, over(week) over(group) asyvars

    but I cannot add SD of the graph (hi and lo) and cannot make twoway command

    Could you please to help me?

    Thank you
    Attached Files

  • #2
    Your data example is too small to show very much, but you're in great danger of creating a plot that is too complicated to be useful. B2M -- whatever that is -- is clearly much larger than the other variables. You already have 3 variables, 3 weeks, 2 groups -- and you want to add SDs too, all while not showing the original data points at all.

    On the design known variously as dynamite, detonator or plunger plots, see e.g. http://biostat.mc.vanderbilt.edu/wik...de/Poster3.pdf

    I don't know why you think you can't make a twoway graph, because that is the way forward.

    stripplot (SSC) offers one convenience command based on twoway.

    Do please use dataex as requested. http://www.statalist.org/forums/help#stata A bigger example would allow more experiment.

    Comment


    • #3
      Thank you for your answer

      This raw data from data command
      dataex ISpre B2M A1M week no group weeks treatment newtreatfirst

      ----------------------- copy starting from the next line -----------------------
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input double ISpre float(B2M A1M) byte(week no group) float weeks str2 treatment float newtreatfirst
       3.71676 78.9  3.029533  4  1 1  0 "WA" 1
        .90282 39.1  4.613963  8  1 1  4 "A"  1
       1.36639 43.6 2.2648203 16  1 1 12 "A"  1
       2.29555 45.1 1.2750412 20  1 1  0 "WB" 2
       3.60489 38.9 2.1587389 24  1 1  4 "B"  2
       1.97568 41.1   .358446 32  1 1 12 "B"  2
      10.30719 68.6  2.922015  4  2 2  0 "WB" 2
       9.35222 50.4 4.4975386  8  2 2  4 "B"  2
       5.94619 43.9 2.2616136 16  2 2 12 "B"  2
       5.47654 49.4 3.1357524 20  2 2  0 "WA" 1
       3.35856 44.5 1.8876172 24  2 2  4 "A"  1
       5.79596 43.5  3.360068 32  2 2 12 "A"  1
       2.34047 51.1  2.139489  4  3 2  0 "WB" 2
       3.08734 43.9  2.385619  8  3 2  4 "B"  2
       3.31328 53.8  2.396514 16  3 2 12 "B"  2
       3.26746 51.4  3.099489 20  3 2  0 "WA" 1
       4.71356 53.1 2.5376284 24  3 2  4 "A"  1
       3.37476 49.8 2.1655452 32  3 2 12 "A"  1
       3.22892 41.2  4.167351  4  4 1  0 "WA" 1
       1.09297 49.4 2.1785896  8  4 1  4 "A"  1
       2.30129 42.1  4.539528 16  4 1 12 "A"  1
        1.8249 38.4         . 20  4 1  0 "WB" 2
       3.05915 28.5  2.394694 24  4 1  4 "B"  2
       1.30267 39.7  3.088947 32  4 1 12 "B"  2
       3.46877 81.5  3.009811  4  5 1  0 "WA" 1
       2.92403 54.9 3.9193275  8  5 1  4 "A"  1
          2.23 64.8 2.2463706 16  5 1 12 "A"  1
       4.07493 62.1 1.1684076 20  5 1  0 "WB" 2
       4.74513 50.8  1.294326 24  5 1  4 "B"  2
        2.3625 53.6 2.6941755 32  5 1 12 "B"  2
        .75846 34.8   4.48895  4  6 2  0 "WB" 2
        .53942 29.2 2.5943484  8  6 2  4 "B"  2
        .85016 34.7  2.989452 16  6 2 12 "B"  2
        .84946 31.6 2.3780382 20  6 2  0 "WA" 1
       2.89958 26.6   2.09975 24  6 2  4 "A"  1
        .65032 30.6  3.132054 32  6 2 12 "A"  1
       5.10559 34.9 4.5853343  4  8 1  0 "WA" 1
       2.01088   28 1.9034988  8  8 1  4 "A"  1
       3.12598 33.9 2.2425535 16  8 1 12 "A"  1
       2.99801 32.4 1.0076634 20  8 1  0 "WB" 2
       3.45853   30  3.468971 24  8 1  4 "B"  2
       4.62195 32.1 1.9647564 32  8 1 12 "B"  2
       3.89271 44.9 1.2437195  4  9 2  0 "WB" 2
       1.47871 41.4  2.974183  8  9 2  4 "B"  2
       1.05174 41.1  2.582284 16  9 2 12 "B"  2
      10.61356 43.3  1.146854 20  9 2  0 "WA" 1
       2.16793 34.9 1.4497387 24  9 2  4 "A"  1
       2.12056 29.5 1.3760028 32  9 2 12 "A"  1
       1.05994 57.9 2.8405814  4 10 1  0 "WA" 1
       1.32252   44  4.047109  8 10 1  4 "A"  1
       3.63074 44.6  2.126129 16 10 1 12 "A"  1
       7.67656 46.1 1.5143996 20 10 1  0 "WB" 2
       4.01183 48.6  2.403769 24 10 1  4 "B"  2
       3.92485   53  1.358987 32 10 1 12 "B"  2
       4.03286 52.4 4.0652404  4 11 1  0 "WA" 1
       3.96437 50.1  3.394368  8 11 1  4 "A"  1
       3.50207 43.3 2.8730276 16 11 1 12 "A"  1
       1.86266 49.3 1.6451358 20 11 1  0 "WB" 2
       2.06006 32.5  3.428132 24 11 1  4 "B"  2
       1.63441 35.3  2.749761 32 11 1 12 "B"  2
        .66305 39.6  2.964004  4 13 2  0 "WB" 2
        .62264 38.8 2.9964504  8 13 2  4 "B"  2
        .60861 39.2  2.771872 16 13 2 12 "B"  2
       2.14573 42.6 4.5070815 20 13 2  0 "WA" 1
        .31896   36  3.046974 24 13 2  4 "A"  1
        .52499 35.9  1.584732 32 13 2 12 "A"  1
       3.02455   35  2.911492  4 14 1  0 "WA" 1
          3.71 44.8  3.112849  8 14 1  4 "A"  1
        3.2299 33.3  1.588832 16 14 1 12 "A"  1
        4.2193   41  4.731342 20 14 1  0 "WB" 2
       2.41453 54.1 1.5541036 24 14 1  4 "B"  2
        1.4966 35.6  3.107097 32 14 1 12 "B"  2
      end
      ------------------ copy up to and including the previous line ------------------
      This was cross-over RCTs, so I analysed this by xtreg , now I want to generate the graph to compared B2M A1M ISpre at weeks 12 and weeks 0 between group 1 and group 2
      I used this commanded
      use "final.dta"
      rename IS weeks
      drop if newtreatfirst == 2
      collapse (mean) ISpre (mean) A1M (mean) B2M (sd) sdis=ISpre (sd) sdam=A1M (sd) sdbm= B2M, by(weeks)
      gen group = 1
      generate hiISpre = ISpre + invttail(12-1,0.025)*(sdis / sqrt(12))
      generate loBM = B2M - invttail(12-1,0.025)*(sdbm / sqrt(12))
      generate hiA1M = A1M + invttail(12-1,0.025)*(sdam / sqrt(12))
      generate loA1M = A1M - invttail(12-1,0.025)*(sdam / sqrt(12))
      generate loISpre = ISpre - invttail(12-1,0.025)*(sdis / sqrt(12))
      generate hiB2M = B2M + invttail(12-1,0.025)*(sdbm / sqrt(12))
      save "collapse_1.dta"
      use "final.dta"
      rename IS weeks
      drop if newtreatfirst == 1
      collapse (mean) ISpre (mean) A1M (mean) B2M (sd) sdis=ISpre (sd) sdam=A1M (sd) sdbm= B2M, by(weeks)
      gen group = 2
      generate hiISpre = ISpre + invttail(12-1,0.025)*(sdis / sqrt(12))
      generate loBM = B2M - invttail(12-1,0.025)*(sdbm / sqrt(12))
      generate hiA1M = A1M + invttail(12-1,0.025)*(sdam / sqrt(12))
      generate loA1M = A1M - invttail(12-1,0.025)*(sdam / sqrt(12))
      generate loISpre = ISpre - invttail(12-1,0.025)*(sdis / sqrt(12))
      generate hiB2M = B2M + invttail(12-1,0.025)*(sdbm / sqrt(12))
      save "collapse_2.dta"
      append using "/Users/doraemengs/Desktop/Research 2017/Sheet/STATA data/collapse_1.dta"
      save "collapse_12.dta"
      graph twoway (bar B2M A1M ISpre weeks)
      twoway (bar ISpre weeks, c(l) yaxis(1)) (bar A1M weeks, c(l) yaxis(1))(bar B2M weeks, c(l) yaxis(2))

      I could separate the group in 1 or 2 when I used command if group == 1 or 2 in the two-way command, but This method had lag of SD and the bar graph of the variables were intersection.

      Could you please to correct this for me?

      Thank you

      TT
      Attached Files

      Comment


      • #4
        Sorry, no more from me on this. You don’t have to take my advice and I don’t have to give more.

        Comment


        • #5
          Thank you for your advice

          I will try it

          Thank you

          Comment

          Working...
          X