Announcement

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

  • Plotting coefficients in ascending or descending order (especially when using marginsplot / coefplot)

    Dear all,

    I often see graphs in which the coefficients are plotted in ascending or descending order. I assume most of these plots are created in R, but I would like to know if this is also possible using Stata. For example when plotting marginal effects I normally use a code like this:

    Code:
    sysuse auto, clear
    
    ssc install coefplot, replace all
    
    reg price i.rep78
    
    margins, dydx(rep78) post
    
    est store ame_rep78
    
    coefplot ame_rep78
    In the created plot the coefficients are sorted by the value of the independent variable (rep78=2, rep78=3,...). However, is there some way to sort/plot the coefficients by their effect (i.e. rep78=3, rep78=4, rep78=2, rep78=5)?

    Thank you very much for your help.

    Michael Jankowski

    (I use Stata 13)

  • #2
    I suppose you could extract the coefficients and their names from the e(b) matrix, sort the values and names accordingly, then pass the resulting namelist to coefplot's order() option.

    Things might be more complicated with marginsplot.

    Best
    Daniel

    Comment


    • #3
      Thanks Daniel!

      Based on your suggestion I have found a solution. My code is as follows and I am pretty sure that there is a more comfortable solution to this. However it works for me and so I am happy

      Code:
      *installing additional packages (if necessary)
      
      ssc install coefplot, replace all
      ssc install matsort, replace all
      
      sysuse auto, clear
      
      reg price i.rep78
      
      margins, dydx(rep78)
      
      matrix plot = r(table)'
      
      matsort plot 1 "down"
      
      matrix plot = plot'
      
      coefplot (matrix(plot[1,])), ci((plot[5,] plot[6,]))
      Thanks once again!

      Michael

      Comment


      • #4
        Supplementary remark: From your two posts I get the impression that you install coefplot from SSC each time you are going to use it. That is not at all necessary; once you have installed it, you have it.

        Comment


        • #5
          Hi Svend,

          I do not do that I just wrote it in the code so that it is replicable for users who haven't installed coefplot.

          Comment


          • #6
            Thanks Michael, this is very helpful for me too as I often intended doing that. It would have been great to have a "sort" type option within the "coefplot" though
            Roman

            Comment

            Working...
            X