Announcement

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

  • coefplot: how to align y-axis and markers?

    Hi,

    I'm using -coefplot- to create a graph showing the balance between covariates for a treatment and control group. I separately regress each covariate on the treatment variable, and store the estimate to plot. Important to my solution is that I can control the names along the y-axis like in my example below.

    Note: I standardize the data so coefficients are comparable across regressions.

    Here is a simple example:

    Code:
    // In this example, I check whether random covariates are balanced across foreign vs. domestic cars
    
    sysuse auto, clear
    
    eststo clear
    
    local variables price mpg headroom trunk
    
    foreach var of local variables {
        egen `var'_std = std(`var')
        eststo: reg `var'_std foreign
    }
    
    coefplot ///
        (est1, rename(foreign = "outcome1"))    ///
        (est2, rename(foreign = "outcome2"))    ///
        (est3, rename(foreign = "outcome3"))    ///
        (est4, rename(foreign = "outcome4")),   ///
        drop(_cons) xline(0) legend(off)             ///
        coeflabel(outcome1 = "Some name" outcome2 = "A different name" outcome3 = "Third name" outcome4 = "Final name")
    As you can see from the output pasted below, the y-axis labels and ticks do not quite line up with the estimates and confidence intervals. Why is that?

    I thought this would be something easy to solve by searching Statalist but I was unsuccessful in finding a solution. Any assistance would be appreciated. Thanks!

    Last edited by Andrew Chan; 15 Dec 2020, 07:46.

  • #2
    Sorry, this is the image I meant to attached to the last post.

    Click image for larger version

Name:	Example.png
Views:	1
Size:	215.4 KB
ID:	1586070

    Comment


    • #3
      The solution was so easy, but discovered with much effort. Posting in case someone else experiences this problem:

      Code:
      // In this example, I check whether random covariates are balanced across foreign vs. domestic cars
      
      sysuse auto, clear
      
      eststo clear
      
      local variables price mpg headroom trunk
      
      foreach var of local variables {
          egen `var'_std = std(`var')
          eststo: reg `var'_std foreign
      }
      
      coefplot ///
          (est1, rename(foreign = "outcome1"))    ///
          (est2, rename(foreign = "outcome2"))    ///
          (est3, rename(foreign = "outcome3"))    ///
          (est4, rename(foreign = "outcome4")),   ///
          drop(_cons) xline(0) legend(off)        ///
          offset(0)                               ///
          coeflabel(outcome1 = "Some name" outcome2 = "A different name" outcome3 = "Third name" outcome4 = "Final name")

      Comment


      • #4
        Originally posted by Andrew Chan View Post
        The solution was so easy, but discovered with much effort. Posting in case someone else experiences this problem:

        Code:
        offset(0)[/COLOR] ///
        coeflabel(outcome1 = "Some name" outcome2 = "A different name" outcome3 = "Third name" outcome4 = "Final name")
        Thank you so much! Your code helped a lot when I was trying to figure out how to align the markers in the coefplot!

        Comment

        Working...
        X