Announcement

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

  • Graphing marginal effects for for only one category

    Hi, I'm trying to produce some graphs of marginal effects but they are almost unreadable. This is my model:

    Code:
    ologit dep_var i.var1##c.var2
    The dep_var has 5 outcomes and var1 has three categories. Ideally, I'd like to produce separate marginal effects graphs for each of the three categories of var1. I've been using this to estimate the marginal effects:

    Code:
    margins, dydx(var1) at(var2=(10(10)120))
    This produces marginal effects for each category other than the base category, but using marginsplot results in a very messy graph. Is there any way to just plot the marginal effects only for one category of var1?

    Thanks

  • #2
    To graph, say, the marginal effect of var1 on outcome 2, at those values of var2, try:

    Code:
    margins, dydx(var1) predict(outcome(2)) at(var2=(10(10)120))
    marginsplot
    You can do the analogous thing for each outcome.

    Comment


    • #3
      Thanks Clyde. I don't think I explained my problem very well. In my case, 'var1' refers to three treatment groups. Let's just call them Group 1 (control group), Group 2 (treatment 1), Group 3 (treatment 2). What I am trying to do is only recover marginal effects for 'treatment 1' so that I can produce a graph just for that group.

      I can do this by creating separate variables for each of the treatment groups. Maybe that's my only solution.

      Comment


      • #4
        Here is an example we can use to discuss and maybe get the plot of interest.
        Code:
        * simulated data
        set seed 17
        set obs 1000
        gen var1 = runiformint(1,3)
        gen var2 = runiformint(10,120)
        gen xb = var1*var2
        sum xb
        replace xb = 3*(xb - r(mean))/(r(max)-r(min)) + rnormal()
        gen dep_var = 1 + (xb>-1) + (xb>0) + (xb>1) + (xb>2)
        
        * model fit
        ologit dep_var var1##c.var2
        
        * marginal effects of var2 on Pr(dep_var==1), at each level of var1
        margins var1, dydx(var2) at(var2=(10(10)120)) predict(outcome(1))
        marginsplot, name(outcome1)
        graph export outcome1.png, replace
        
        * marginal effects of var2 on Pr(dep_var==2), at each level of var1
        margins var1, dydx(var2) at(var2=(10(10)120)) predict(outcome(2))
        marginsplot, name(outcome2)
        graph export outcome2.png, replace
        Here are the resulting graphs.
        Attached Files

        Comment


        • #5
          I misread the details in #3.
          Here is another attempt.
          Code:
          * simulated data
          set seed 17
          set obs 1000
          gen var1 = runiformint(1,3)
          gen var2 = runiformint(10,120)
          gen xb = var1*var2
          sum xb
          replace xb = 3*(xb - r(mean))/(r(max)-r(min)) + rnormal()
          gen dep_var = 1 + (xb>-1) + (xb>0) + (xb>1) + (xb>2)
          
          * model fit
          ologit dep_var var1##c.var2
          
          * marginal effects of treatement1 on Pr(dep_var==1), at some levels of var2
          margins r(1 2).var1, at(var2=(10(10)120)) predict(outcome(1))
          marginsplot, name(outcome1)
          graph export outcome1.png, replace
          
          * marginal effects of treatement1 on Pr(dep_var==2), at some levels of var2
          margins r(1 2).var1, at(var2=(10(10)120)) predict(outcome(2))
          marginsplot, name(outcome2)
          graph export outcome2.png, replace
          And the corresponding plots:
          Attached Files

          Comment

          Working...
          X