Announcement

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

  • Can I plot estimates on top of one another rather than side by side?

    Dear Statalist,

    I have a query about editing the output of a graph. I have some estimates that compare the outcomes of two separate treatment arms to a control group (Treat = group1,group2). The estimates themselves are then saved in separate matrices (matrix A and B), then plotted together for each outcome. Naturally, coefplot accomplishes this task. However, the default is that coefplot will plot each input (matrix) side by side. Is it possible to edit the position of the estimates so that they are stacked/aligned/on the same x-coordinate rather than side by side? Ideally, one of the group of estimates would be shifted to the left (to align with the value marker) and the other would be shifted to the right (to do the same).

    Below, I have generated some code similar to my own using some sysuse data. The resulting figure is below as well.

    I'm stumped here, so hopefully, someone has some good idea!

    Code:
    clear all
    cap ssc install coefplot
    
    sysuse xtline1
    tsset person day
    tab person
    gen month = month(day)
    gen rl_time = month - 6
    tab rl
    gen treat = 0
    replace treat = 1 if person == 1
    replace treat = 2 if person == 2
    tab treat
    
    forvalues  t= -5/-2{
        local abs = abs(`t')
        gen rl_m`abs' = rl_time == `t'
    }
    forvalues t =0/6{
        gen rl_p`t' = rl_time == `t'
    }
    
    reg calories i.treat##(rl_m* rl_p*)
    
    forvalues t=-5/-2{
        local abs = abs(`t')
        local b1 = _b[1.treat#1.rl_m`abs']
        local b2 = _b[2.treat#1.rl_m`abs']
        cap matrix A = A, `b1'
        if _rc !=0{
            matrix A = `b1'
        }
        cap matrix B = B, `b2'
        if _rc !=0{
            matrix B = `b2'
        }
    }
    
    coefplot matrix(A) matrix(B), vert
    Click image for larger version

Name:	example.png
Views:	1
Size:	29.1 KB
ID:	1753603

    Last edited by ezra goldstein; 16 May 2024, 12:22.

  • #2
    remove the "vert"

    Comment


    • #3
      Originally posted by George Ford View Post
      remove the "vert"
      Hi George,

      Thanks for the comment. Let me clarify. I don't mean to say I want the estimates horizontal rather than vertical. If plotted without vert, the estimates would need to then be on the same y-coordinate. I still want the point estimates to be displayed as they are, such that the y-axis labels them. I want the blue and red estimates to be on the same x-coordinate, such that they are literally plotted together rather than side by side.
      Last edited by ezra goldstein; 16 May 2024, 12:41. Reason: Edited for additional clarity.

      Comment


      • #4
        offset(0).

        you may want to mlabel.

        Comment


        • #5
          Originally posted by George Ford View Post
          offset(0).

          you may want to mlabel.
          George... my hero!

          Adding offset(0) did the trick. Never knew of such an option.

          Thank you!

          Comment


          • #6
            It's in the help file, along with several other options you may find useful.

            Comment


            • #7
              Just wanted to say thank you! I tried offset(0) since I had exactly the same question as Ezra. Amazing!

              Comment

              Working...
              X