Announcement

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

  • -coefplot- for margins from multiple models

    I want to create a -coefplot- from margins from four models, e.g.
    Code:
    fracreg probit y x_[1]
    margins, dydx(x_[1])
    est store mod1
    
    fracreg probit y x_[2]
    margins, dydx(x_[2])
    est store mod2
    
    fracreg probit y x_[3]
    margins, dydx(x_[3])
    est store mod3
    
    fracreg probit y x_[4]
    margins, dydx(x_[4])
    est store mod4
    
    coefplot mod1 mod2 mod3 mod4
    This approach only gives the coefficients from the regression model, not dy/dx from margins. NB: I am working on a secure server where -install ssc- does not work.

  • #2
    You have to post the margins results to e(b). See the -post- option for that.

    Comment


    • #3
      Andrew is exactly right, but here is why. When you run an estimation command, it produces matrices called e(b), the matrix of your parameter estimates, and e(V), the variance-covariance matrix of the estimators. You get the SE, and thus your p-values, from the variance of the estimators.

      When you run margins, it does not automatically post e(b) and e(V) unless you manually specify that. coefplot needs those matrices to produce plots.

      However, when you use margins with its normal syntax, you can repeatedly run the margins command with different specifications because margins draws from the e(b) and e(V) matrices that the base estimation command posted to memory. When you tell margins to post its e(b) and e(V) matrices, you'll have to re-run your original estimation command if you want to re-specify margins. To avoid that, you can store the estimates from the base regression model.
      Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

      When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

      Comment


      • #4
        Thanks for your feedback which made it easier to understand the necessary components for the plot. I found the solution to -coefplot- with multiple margins results by following the approach outlined in this post (#6/#9, identical results).

        Code:
        eststo raw: fracreg probit y x_[1]
        eststo margin1: margins, dydx(x_[1]) post
        estimates store m1, title(Model 1)
        
        eststo raw: fracreg probit y x_[2]
        eststo margin2: margins, dydx(x_[2])
        estimates store m2, title(Model 2)
        
        eststo raw: fracreg probit y x_[3]
        eststo margin3: margins, dydx(x_[3]) post
        estimates store m3, title(Model 3)
        
        eststo raw: fracreg probit y x_[4]
        eststo margin4: margins, dydx(x_[4]) post
        estimates store m4, title(Model 4)
        
        coefplot m1 m2 m3 m4, nooff
        // or
        coefplot margin1 margin2 margin3 margin4, nooff
        Last edited by Tarjei W. Havneraas; 10 Mar 2021, 15:19.

        Comment

        Working...
        X