Announcement

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

  • Coefplot: sort coefficients from different models

    Hi all,

    I've seen this question get asked a few times (e.g. here), but I have been unable to find an answer anywhere. When using coefplot to graph coefficients from multiple models, how do I sort these by the size of the point estimate?

    The sort option only seems to allow sorting based on the same model/equation. Any help here would be highly appreciated!

    here's a quick example:
    Code:
    sysuse auto, clear
    *run a few models
    forvalues i=3/5 {
        eststo reg_`i': reg price mpg if rep78==`i'
        }
     
    *plot regression coefficient (sort option added, but as described, that doesn't do anything)
     coefplot reg_*, keep(mpg) sort()
    Thanks,
    John

  • #2
    In case this helps as a starting point I've fought around with matrices and have arrived at half a solution that lets me graph the point estimates, but they're all on the same point on the x axis and therefore I cannot distinguish CIs (see code below). Again, any help would be highly appreciated!

    Code:
    cap ssc install matsort
    sysuse auto, clear
    
    forvalues i=3/5 {
        eststo reg_`i': reg price mpg if rep78==`i'
        matrix test = r(table)'
        matrix test`i' = test[1,1...]
    
        }
    matrix coefs = (test3 \ test4 \ test5)
    matsort coefs 1 "down"
        coefplot (matrix(coefs[,1]))    , ci((coefs[,5] coefs[,6]))

    Comment


    • #3
      coefplot is from SSC, as you are asked to explain (FAQ Advice #12). You need to be able to distinguish the coefficients and how you do this is by their names. Here is an approach from your example.

      Code:
      sysuse auto, clear
      *run a few models
      forvalues i=3/5 {
          rename * *_`i'
          eststo reg_`i': reg price mpg if rep78==`i'
          rename *_`i' *
      }
      set scheme s1color
      coefplot reg_*, keep(mpg*) sort ylab("") ytitle("mpg", orient(horiz))
      Res.:

      Click image for larger version

Name:	Graph.png
Views:	1
Size:	32.9 KB
ID:	1620740

      Comment


      • #4
        Thanks Andrew Musau -- highly appreciated!

        Comment

        Working...
        X