Announcement

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

  • [coefplot]: Changing distance between outcome coefficients

    I have a question regarding Ben Jann's user-written package coefplot, downloaded from SSC.

    I am using coefplot to display coefficients from different outputs. Is it possible to adjust the spacing between coefficients from different outputs? Let me illustrate with an example (taken from the help file):
    Code:
    sysuse auto, clear
    gen mpp = mpg/8
    mlogit rep78 mpp i.foreign if rep>=3
    coefplot, nolabel keep(3:*.foreign 4:mpp 5:mpp _cons) omitted baselevels
    How can I vary the distance (red lines) between the coefficients of outcome 3 and outcome 4, and between outcome 4 and outcome 5? This is the output:
    Click image for larger version

Name:	Screenshot 2025-08-29 161754.png
Views:	1
Size:	30.4 KB
ID:	1781403

    Any insights (or tricks) would be much appreciated.

    Thank you very much.
    Giacomo



  • #2
    Try the relocate() option to coefplot?

    Comment


    • #3
      Originally posted by Hemanshu Kumar View Post
      Try the relocate() option to coefplot?
      Good suggestion, Hemanshu. Thank you. Unfortunately I learnt that relocate()works after inserting gaps between equations. The coefplot's help under relocate()specifies:

      Note that the specified positions are assigned before inserting gaps between equations, headings,and groups [...]
      Here is an example:
      Code:
      coefplot, nolabel keep(4:mpp 5:mpp _cons) relocate(4:mpp=1 5:mpp=1.1 5:_cons=1.2) omitted baselevels
      Click image for larger version

Name:	Screenshot 2025-08-30 134908.png
Views:	1
Size:	22.1 KB
ID:	1781422

      Comment


      • #4
        Giacomo Zanello From your example I can't tell exactly what you're trying to accomplish , but generally coefplot has a few design layout approaches that allow for moving around plots/labels using the offset() and other similar options. You may consider one of these ways of nesting your coefficients or models below to see if this is more flexible . Ben Jann has several Stata presentations and his website that provides some examples (including for mlogit) similar to the ones I provide below - I advise looking to those for more guidance than is available in the -help coefplot- for mlogit type outputs. Check out slides 27-33 in this presentation for instance: https://www.stata.com/meeting/german.../de14_jann.pdf


        Code:
        sysuse auto, clear
        gen mpp = mpg/8
        mlogit rep78 mpp i.foreign if rep>=3, coefleg
        est sto m1
        **this allows for options to be nested with the coefficients like offset() label() etc**
         coefplot (., keep(3:*.foreign) ) (., keep(4:*)) (., keep(5:*) lab(five)) , omitted baselevels nolabel
        
        *or*
        
        coefplot (m1, keep(*4:*)) (m1, lab(value=5) keep(*5:*) offset(.1)) ///
         , nolabel  omitted baselevels  xline(0)
        
        **other ways of grouping results include:
        coefplot ., keep(3:*)  bylabel(Value 3)  || ///
                 ., keep(4:*) bylabel(Value 4) || ///
                 ., keep(5:*) bylabel(Value 5) ||, baselevels omitted byopts(c(3) imargin(0))
        Last edited by eric_a_booth; Yesterday, 08:58.
        Eric A. Booth | Senior Director of Research | Far Harbor | Austin TX

        Comment


        • #5
          Thank you very much for the suggestions, Eric. The solutions you propose do not quite achieve what I am trying to do. I would like to control the distance between coefficients from different outcomes (I highlighted this distance in red in the examples I shared). This spacing seems to be fixed, possibly for good reasons.

          By way of background, I am working with a more complex graph (see below) that presents results from a series of models estimating factors influencing the consumption of individual food items (i.e. Groups A and B and Cat 1 and 2), by Country. With some cosmetic tweaks, I think the graph could work well for my purposes if I could reduce the empty space between the two outcomes (Cat 1 and Cat 2). Otherwise, I may need to reconsider how to present the results.

          Click image for larger version

Name:	Screenshot 2025-08-30 190154.png
Views:	1
Size:	96.9 KB
ID:	1781453
          Last edited by Giacomo Zanello; Yesterday, 12:17.

          Comment


          • #6
            I think this may come down to cleverly using options like swapnames , rename() and eqrename() to leverage the fact that spacing can be fairly accurately specified within equations, even if not across equations.

            Consider for instance
            Code:
            coefplot, nolabel keep(4:mpp 5:mpp _cons) rename(4:mpp=mpp1 5:mpp=mpp2) eqrename(4 5 = 1) omitted baselevels relocate(mpp1=1 mpp2=2 _cons=4)
            which produces:
            Click image for larger version

Name:	Screenshot 2025-08-31 at 12.50.29 AM.png
Views:	1
Size:	317.8 KB
ID:	1781455

            Comment


            • #7
              Originally posted by Hemanshu Kumar View Post
              Consider for instance
              Code:
              coefplot, nolabel keep(4:mpp 5:mpp _cons) rename(4:mpp=mpp1 5:mpp=mpp2) eqrename(4 5 = 1) omitted baselevels relocate(mpp1=1 mpp2=2 _cons=4)
              This is very helpful, Hemanshu -- Very clever trick. I think you put me on the right path. Thank you very much.

              Comment

              Working...
              X