Announcement

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

  • coefplot for two average marginal effects

    I'm using the excellent user-written -coefplot- by Ben Jann to graph some average marginal effects after margins. I've used it for this purpose before with the -post- option, but now I'm trying to plot the average marginal effects of two different variables by a categorical variable and I'm having some trouble.

    The code is something like this:

    Code:
    regress wages i.education##c.percent_white i.education##c.percent_service_work controlvar_ab
    margins, dydx (percent_white percent_service_work) over(education) vce(unconditional) post
    estimates store lag2
    
    regress wages i.education##c.percent_white i.education##c.percent_service_work controlvar_yz
    margins, dydx (percent_white percent_service_work) over(education) vce(unconditional) post
    estimates store lag5
    
    coefplot lag2 lag5
    For some reason, this only gives me the average marginal effects for percent_white, leaving out the average marginal effects for percent_service_work. When I do:

    Code:
    coefplot lag2 lag5, keep(percent_service_work)
    Or if I use:

    Code:
    coefplot lag2 lag5, keep(percent_white)
    I get the "no coefficients found, all dropped, or none kept" message. So something is going on where coefplot is only reading the percent_white AME by education level, and then plotting it.

    For what it's worth, I get the same thing if I use eststo instead of estimates store. It's also a problem if I don't use the over option and instead do it this way:

    Code:
    margins education, dydx (percent_white percent_service_work) vce(unconditional) post
    I'm sure the solution to this is super simple, but for some reason I can't seem to figure out how to do it. Thank you for your time in advance.

    Best,
    Jonathan

  • #2
    I think the only way this might work is to predict percent_white, then predict percent_service work, and save them separately? But then I'm not sure how to combine them back together on the graph without messing with the matrices.

    Comment


    • #3
      Provide a reproducible example. See FAQ Advice #12 for details.

      Comment


      • #4
        Here is an example of what I am talking about:

        Code:
        clear
        
        sysuse auto.dta
        
        regress price i.rep78##c.mpg i.rep78##c.headroom trunk
        margins, dydx (mpg headroom) over(rep78) post
        estimates store m1
        
        
        regress price i.rep78##c.mpg i.rep78##c.headroom length
        margins, dydx (mpg headroom) over(rep78) post
        estimates store m2
        
        
        coefplot m1 m2
        This provides the average marginal effects for mpg by rep78 for both models, but not headroom by rep78.
        Click image for larger version

Name:	sample graph.png
Views:	1
Size:	47.4 KB
ID:	1751774

        Comment


        • #5
          You have multiple equations, so spell them out.

          Code:
          clear
          
          sysuse auto.dta
          
          regress price i.rep78##c.mpg i.rep78##c.headroom trunk
          margins, dydx (mpg headroom) over(rep78) post
          estimates store m1
          
          
          regress price i.rep78##c.mpg i.rep78##c.headroom length
          margins, dydx (mpg headroom) over(rep78) post
          estimates store m2
          
          coefplot m1 m2, keep(mpg: headroom:) eqlab(, angle(vert))
          Click image for larger version

Name:	Graph.png
Views:	1
Size:	37.1 KB
ID:	1751784

          Comment


          • #6
            Thanks. So to summarize, the problem is that if you just put in:

            Code:
            coefplot m1 m2, keep(mpg headroom)
            Nothing it happens--coefplot doesn't know mpg and headroom exist. But if you do:

            Code:
            coefplot m1 m2, keep(mpg: headroom:)
            With the colons after the interaction terms, then it knows where to look.

            Comment


            • #7
              In Stata matrices holding estimation results, equations are identified by equation name preceding a colon, e.g., "mpg:". So you want to tell coefplot to keep a particular equation as the default is to keep only the first equation. If you want to keep all equations, you can use an asterisk (*) as a wildcard.

              Code:
              coefplot m1 m2, keep(*:)

              Comment

              Working...
              X