Announcement

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

  • How do I annotate the mean value on my mi‐imputation plot?

    I’ve looped over 20 imputations, stored the onview coefficient in a small frame, computed the across‐imputation mean, and then plotted
    Code:
    frame coefs {
      quietly summarize onview, meanonly
      local mean_onview = r(mean)
     
      twoway ///
        (scatter onview imp) ///                                 // the 20 points  
        (function y=`mean_onview', range(1 20) lpattern(dot)), /// // dotted mean‐line  
        yline(0, lpattern(dash)) ///                             // zero‐line  
        title("Coefficient on onview Across 20 Imputations") ///
        xlabel(1(1)20, grid) ///
        ylabel(, grid) ///
        xtitle("Imputation #") ///
        ytitle("Estimate of onview") ///
        legend(off)
    }
    But I get only the points and lines—no numeric labels at the mean. What am I missing? Any advice would be greatly appreciated!
    Last edited by DY Kim; Yesterday, 15:50.

  • #2
    No need to use tw function here. You can have several -yline()- options. Otherwise, if you want to indicate the mean value on the axis, you have to be explicit. Also note that you will increase your chances of obtaining helpful replies by enclosing a reproducible example, as recommended in FAQ Advice #12.

    Code:
    sysuse auto, clear
    qui sum mpg
    local mean_mpg= r(mean)
    tw scatter mpg weight, yline(`mean_mpg', lp(dot)) ylab(`mean_mpg' "`:di %3.2f `mean_mpg''")
    Res.:
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	41.2 KB
ID:	1776757

    Comment


    • #3
      Thank you for the help. Your code successfully returned the mean value.
      Code:
      frame coefs {
      qui sum onview
      local mean_onview= r(mean)
      
      tw scatter onview imp, ///
      yline(`mean_onview', lp(dot)) ///
      ylab(`mean_onview' "`:di %3.2f `mean_onview''", grid) ///
      xlabel(1(1)10, grid) ///
      legend(off)  
      }
      However, Stata removes all default y-axis ticks and displays only the tick at the mean that I specified. How can I add a tick mark—and its label and value—at the mean while preserving the remainder of the axis ticks? Here’s a reproducible data.
      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input float(imp onview)
       1  -.03763065
       2  -.03751088
       3    -.037388
       4  -.03709687
       5  -.03756259
       6 -.037001435
       7 -.037054714
       8 -.036965605
       9  -.03744491
      10 -.037167422
      end
      Last edited by DY Kim; Today, 08:53.

      Comment


      • #4
        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input float(imp onview)
         1  -.03763065
         2  -.03751088
         3    -.037388
         4  -.03709687
         5  -.03756259
         6 -.037001435
         7 -.037054714
         8 -.036965605
         9  -.03744491
        10 -.037167422
        end
        
        qui sum onview
        local mean_onview= r(mean)
        
        tw scatter onview imp, ///
        yline(`mean_onview', lp(dot)) ///
        ylab(`mean_onview' "`:di %3.2f `mean_onview''", grid add) ///
        xlabel(1(1)10, grid) ///
        legend(off)
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	44.4 KB
ID:	1776782

        Comment


        • #5
          Naturally, you should use a display format matching the axis labels. In this case:

          Code:
          ylab(`mean_onview' "`:di %6.5g `mean_onview''", grid add)
          Click image for larger version

Name:	Graph.png
Views:	1
Size:	44.7 KB
ID:	1776784
          Last edited by Andrew Musau; Today, 09:56.

          Comment

          Working...
          X