Announcement

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

  • Average marginal effect interaction interpretation

    Apologies- I am not quite sure how to properly phrase my question.

    I want to know the average marginal effect of SES by female. At the same time, I want to know the average marginal effect of read and science (unconstrained by female). Is there a way to do this with one line of code? And is this necessary? Shouldn't the AMEs of read and science be unaffected by whether I examine the AMEs of SES by female?

    HTML Code:
    use https://stats.idre.ucla.edu/stat/data/hsbdemo
    logit honors i.female##i.ses read science 
    margins, dydx(ses) at(female=(0 1))
    logit honors i.female##i.ses read science 
    margins, dydx(*)
    Also, can you please clarify the interpretation of the interaction. Is the following correct? Relative to males, the predicted probablity of females who go from low to middle SES entering the honors program is -.17 lower?

  • #2
    I don't know of any way to get this done in a single command.

    And is this necessary? Shouldn't the AMEs of read and science be unaffected by whether I examine the AMEs of SES by female
    Actually, it is necessary. If your regression were a linear regression, then the average marginal effects of read and science would be independent of female in the absence of an interaction term. But in a non-linear model, the marginal effect can depend on the starting outcome level, and the overall outcome level will differ between males and females--which in turn will cause the average marginal effects of read and science to depend on the value of female.

    If you were calculating the average marginal effect on xb instead of on the outcome probability, then the result would be the same for males and females in the absence of an interaction term. See this example similar to your own:
    Code:
    . webuse nlswork, clear
    (National Longitudinal Survey of Young Women, 14-24 years old in 1968)
    
    .
    . logit union i.collgrad##i.nev_mar grade age
    
    Iteration 0:  Log likelihood = -10462.395  
    Iteration 1:  Log likelihood = -10409.206  
    Iteration 2:  Log likelihood =  -10408.95  
    Iteration 3:  Log likelihood =  -10408.95  
    
    Logistic regression                                     Number of obs = 19,216
                                                            LR chi2(5)    = 106.89
                                                            Prob > chi2   = 0.0000
    Log likelihood = -10408.95                              Pseudo R2     = 0.0051
    
    ----------------------------------------------------------------------------------
               union | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    -----------------+----------------------------------------------------------------
          1.collgrad |   .3673665   .0713982     5.15   0.000     .2274287    .5073044
           1.nev_mar |   .2079362   .0507878     4.09   0.000      .108394    .3074784
                     |
    collgrad#nev_mar |
                1 1  |  -.2795004   .0994412    -2.81   0.005    -.4744015   -.0845992
                     |
               grade |    .010484   .0117392     0.89   0.372    -.0125244    .0334924
                 age |   .0096602   .0029157     3.31   0.001     .0039455     .015375
               _cons |  -1.728069   .1643183   -10.52   0.000    -2.050127   -1.406012
    ----------------------------------------------------------------------------------
    
    .
    . margins collgrad, dydx(nev_mar grade age)
    
    Average marginal effects                                Number of obs = 19,216
    Model VCE: OIM
    
    Expression: Pr(union), predict()
    dy/dx wrt:  1.nev_mar grade age
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |      dy/dx   std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
    0.nev_mar    |  (base outcome)
    -------------+----------------------------------------------------------------
    1.nev_mar    |
        collgrad |
              0  |   .0372316   .0093999     3.96   0.000     .0188081    .0556552
              1  |  -.0143233   .0172126    -0.83   0.405    -.0480593    .0194128
    -------------+----------------------------------------------------------------
    grade        |
        collgrad |
              0  |   .0018134    .002041     0.89   0.374    -.0021869    .0058137
              1  |   .0021184   .0023315     0.91   0.364    -.0024511     .006688
    -------------+----------------------------------------------------------------
    age          |
        collgrad |
              0  |   .0016709   .0005045     3.31   0.001      .000682    .0026598
              1  |    .001952   .0005892     3.31   0.001     .0007973    .0031067
    ------------------------------------------------------------------------------
    Note: dy/dx for factor levels is the discrete change from the base level.
    
    . margins collgrad, dydx(nev_mar grade age) predict(xb)
    
    Average marginal effects                                Number of obs = 19,216
    Model VCE: OIM
    
    Expression: Linear prediction (log odds), predict(xb)
    dy/dx wrt:  1.nev_mar grade age
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |      dy/dx   std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
    0.nev_mar    |  (base outcome)
    -------------+----------------------------------------------------------------
    1.nev_mar    |
        collgrad |
              0  |   .2079362   .0507878     4.09   0.000      .108394    .3074784
              1  |  -.0715642   .0867682    -0.82   0.409    -.2416268    .0984984
    -------------+----------------------------------------------------------------
    grade        |
        collgrad |
              0  |    .010484   .0117392     0.89   0.372    -.0125244    .0334924
              1  |    .010484   .0117392     0.89   0.372    -.0125244    .0334924
    -------------+----------------------------------------------------------------
    age          |
        collgrad |
              0  |   .0096602   .0029157     3.31   0.001     .0039455     .015375
              1  |   .0096602   .0029157     3.31   0.001     .0039455     .015375
    ------------------------------------------------------------------------------
    Note: dy/dx for factor levels is the discrete change from the base level.
    It's the non-linearity of the -logit- link that creates the difference.

    Relative to males, the predicted probablity of females who go from low to middle SES entering the honors program is -.17 lower?
    As you do not show the results that you are trying to interpret, I cannot say whether you are right or not.

    Comment


    • #3
      Thank you for your helpful response, Clyde. Would you be able to help regarding the following interpretation and code questions?


      Does this produces the predicted probability of union for all variables in model?
      Code:
      . do "/var/folders/cx/24gfp4_13vqc86wb4bjhr2h80000gn/T//SD01751.000000"
      
      . webuse nlswork, clear
      (National Longitudinal Survey of Young Women, 14-24 years old in 1968)
      
      . logit union i.collgrad##i.nev_mar grade age
      
      Iteration 0:  Log likelihood = -10462.395  
      Iteration 1:  Log likelihood = -10409.206  
      Iteration 2:  Log likelihood =  -10408.95  
      Iteration 3:  Log likelihood =  -10408.95  
      
      Logistic regression                                     Number of obs = 19,216
                                                              LR chi2(5)    = 106.89
                                                              Prob > chi2   = 0.0000
      Log likelihood = -10408.95                              Pseudo R2     = 0.0051
      
      ----------------------------------------------------------------------------------
                 union | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
      -----------------+----------------------------------------------------------------
            1.collgrad |   .3673665   .0713982     5.15   0.000     .2274287    .5073044
             1.nev_mar |   .2079362   .0507878     4.09   0.000      .108394    .3074784
                       |
      collgrad#nev_mar |
                  1 1  |  -.2795004   .0994412    -2.81   0.005    -.4744015   -.0845992
                       |
                 grade |    .010484   .0117392     0.89   0.372    -.0125244    .0334924
                   age |   .0096602   .0029157     3.31   0.001     .0039455     .015375
                 _cons |  -1.728069   .1643183   -10.52   0.000    -2.050127   -1.406012
      ----------------------------------------------------------------------------------
      
      . margins, dydx(*) 
      
      Average marginal effects                                Number of obs = 19,216
      Model VCE: OIM
      
      Expression: Pr(union), predict()
      dy/dx wrt:  1.collgrad 1.nev_mar grade age
      
      ------------------------------------------------------------------------------
                   |            Delta-method
                   |      dy/dx   std. err.      z    P>|z|     [95% conf. interval]
      -------------+----------------------------------------------------------------
        1.collgrad |   .0586915   .0134095     4.38   0.000     .0324093    .0849736
         1.nev_mar |   .0268866   .0083423     3.22   0.001      .010536    .0432371
             grade |   .0018703   .0020941     0.89   0.372    -.0022341    .0059747
               age |   .0017233   .0005198     3.32   0.001     .0007046    .0027421
      ------------------------------------------------------------------------------
      Note: dy/dx for factor levels is the discrete change from the base level.
      Additionally, is my understanding correct that...
      This produces the predicted probability of union for nev_mar##collgrad, grade##collgrad, and age##collgrad?
      And interpretation is that getting married decreases the predicted probability of union participation by -.014 for college grads?
      And that a one-year increase in age increases the predicted probability of union participation by .0016 for non-college grads?

      Code:
      . margins collgrad, dydx(nev_mar grade age) 
      
      Average marginal effects                                Number of obs = 19,216
      Model VCE: OIM
      
      Expression: Pr(union), predict()
      dy/dx wrt:  1.nev_mar grade age
      
      ------------------------------------------------------------------------------
                   |            Delta-method
                   |      dy/dx   std. err.      z    P>|z|     [95% conf. interval]
      -------------+----------------------------------------------------------------
      0.nev_mar    |  (base outcome)
      -------------+----------------------------------------------------------------
      1.nev_mar    |
          collgrad |
                0  |   .0372316   .0093999     3.96   0.000     .0188081    .0556552
                1  |  -.0143233   .0172126    -0.83   0.405    -.0480593    .0194128
      -------------+----------------------------------------------------------------
      grade        |
          collgrad |
                0  |   .0018134    .002041     0.89   0.374    -.0021869    .0058137
                1  |   .0021184   .0023315     0.91   0.364    -.0024511     .006688
      -------------+----------------------------------------------------------------
      age          |
          collgrad |
                0  |   .0016709   .0005045     3.31   0.001      .000682    .0026598
                1  |    .001952   .0005892     3.31   0.001     .0007973    .0031067
      ------------------------------------------------------------------------------
      Note: dy/dx for factor levels is the discrete change from the base level.
      Additionally, I understand that non-linear models will be affected by whether the interaction is included. Are you familiar with a way then to write a command that achieves following all at once?
      AME of collgrad*nev_mar and AME of all other variables in model without interaction?

      Thank you. I appreciate the help

      Comment


      • #4
        Does this produces the predicted probability of union for all variables in model?
        No. It does not produce predicted probabilities. It produces average marginal effects for all model variables. If you want the predicted probabilities for both values of collgrad, the code would be -margins collgrad-. Note the absence of any -dydx()- option when calculating predicted probabilities. Similarly -margins nev_mar- will give you the predicted probabilities for both values of nev_mar. For the variables grade and age, which are continuous variables, you have to specify which values of grade and age you want to calculate the predicted probabilities for. For example, -margins, at(age = (40(5)60))- will get you the predicted probabilities at age = 40, 45, 50, 55, and 60. And so on.

        Additionally, is my understanding correct that...
        This produces the predicted probability of union for nev_mar##collgrad, grade##collgrad, and age##collgrad?
        No. Again, you are calculating average marginal effects with your code, not predicted probabilities.

        And interpretation is that getting married decreases the predicted probability of union participation by -.014 for college grads?
        Sort of. I think you have the idea, but your wording is wrong. If you get married, the value of nev_mar changes from 0 to 1, and for college grads, that change from 0 to 1 is associated with a -0.014 difference in probability of union participation. But a -0.014 difference is properly referred to as a decrease of 0.014, not as a decrease of -0.014. (A decrease of -0.014 would actually be an increase of 0.014.) On top of that, the use of causal language is not appropriate for results derived solely from observational data.

        And that a one-year increase in age increases the predicted probability of union participation by .0016 for non-college grads?
        Again, you have the idea, but you erred by using causal language (as you did in the previous example as well). This data set is observational data, so you cannot say that anything increases or decreases anything else. You must say that a one-year increase in age is associated with an increase in predicted probability of union participation by .0016 for non-college grads.

        Additionally, I understand that non-linear models will be affected by whether the interaction is included. Are you familiar with a way then to write a command that achieves following all at once?
        AME of collgrad*nev_mar and AME of all other variables in model without interaction?
        No, I'm not, and neither is anybody else. That's because there is no such thing as the AME of collgrad*nevmar. Interaction terms never have a marginal effect of their own. Here's a simple way to understand why. If collgrad*nevmar had a marginal effect, it would be the difference in union participation probability associated with a unit difference in collgrad*nevmar. But here's the problem. There are three different ways that collgrad*nevmar can change from 0 to 1: we can start with collgrad = 0 & nevmar = 0 and change to collgrad = 1 & nevmar = 1. But we could also start with collgrad = 1 and nevmar = 0 or with collgrad = 0 and nevmar = 1 and change to collgrad = 1 & nevmar = 1. A little bit of arithmetic will show you that all three of those differences are associated with different changes in union probability. So, there is no one marginal effect for collgrad*nevmar: there are three different ones. Another important observation here is that marginal effects are interpreted as differences in outcome probability associated with unit difference in the variable whose marginal effect we are discussing with all other variables held constant. But is isn't even theoretically possible for collgrad*nevmar to change while collgrad and nevmar themselves remain constant. So always remember that interaction terms never have a marginal effect. The concept of marginal effect simply does not apply to them.

        Comment


        • #5
          As a quick side note, ginteff might be helpful for you, see: https://journals.sagepub.com/doi/10....6867X231175253
          Best wishes

          (Stata 16.1 MP)

          Comment


          • #6
            Thank you Felix, I'm still working through understanding ginteff. This is helpful.

            Thanks also Clyde. I'll take note of avoiding casual language (associated change in predicted probability) and properly referring to change in difference (rather than decrease -0.014).

            Would you be able to clarify if my understanding is correct:

            Code:
            webuse nlswork, clear
            logit union i.collgrad##i.nev_mar grade age
            mtable, at(nev_mar=1) rowname(nev_mar=1) statistics(ci) estname(Pr_LFP) 
            mtable, at(nev_mar=0) rowname(nev_mar=0) statistics(ci) estname(Pr_LFP) below
            mtable, dydx(nev_mar) rowname(hereis) statistics(ci) estname(Pr_LFP) below brief
            // predicted probability of union if all married
            // predicted probablity of union if none married
            // This is the average marginal effect. The AME is the change from not married to married on the predicted probability of union?

            Code:
            logit union i.collgrad i.nev_mar grade age
            margins, dydx(*) // this produces AME for all variables in model
            To confirm, dydx(*) first computes the change in union (DV) as collgrad changes (IV), holding all other variables constant (never_mar, grade, and age) constant. Then it separately computes the change in union (DV) as never_mar changes (IV) holding all other variables constant (collgrad, grade, and age). And continues with this process until the AMEs for all predictors in model are independently computed while holding the other predictors constant?

            Is it accurate to say that dydx(*) is computing the AME of each predictor, holding all other predictors at their actual value (asobserved)?

            In regard to my other Q, it may be better that I describe the issue that I am trying to solve. I was seperatedly estimating logit models of likelihood of union participation by collgrad. In particular, I am interested in whether effect of nev_mar differs by collgrad. However, I realized that it was inappropriate to compare AMEs from seperate models. While Mecompare (net install) initally seemed like the solution, it does not appear to work with weighted data. Thus, I thought I'd do one model with those who did and didn't attend college and use an interaction of collgrad*never_mar.

            My understanding for our conversation is it is not possible to get an AME of an interaction. Is there another solution to achieve what I am attempting?

            Thank you!

            Comment


            • #7
              I cannot give reliable answers to your questions about -mtable-, as I am not familiar with the command. A little searching enabled me to learn that it is part of the -spost13- package on SSC and I was able to peruse the help file. It seems that -mtable- is a wrapper for the -margins- command and gathers results and assembles them into output tables. On the, I think, reasonable assumption that it does not alter the syntax and semantics of the various options of -margins-, then I would believe the following:
              // predicted probability of union if all married
              // predicted probablity of union if none married
              Nearly correct. The variable is actually called nev_mar and refers to never being married, So the contrast here is not between all married and none married but between all those who have never been married and those have, at some point being married. This difference is important as people who are currently divorced or widowed are not married, are handled differently by nev_mar than they would be by a married variable. So the variable nev_mar is actually contrasting people who either are currently or at some earlier time were married to those who have never been married. I should have raised this same concern in my responses in #4, but I was preoccupied with other issues.

              // This is the average marginal effect.
              Correct.

              The AME is the change from not married to married on the predicted probability of union?
              Nearly correct. The nlswork data set is longitudinal survey data. In addition to what I said in the preceding paragraph about the actual meaning of the nev-mar variable, a difference between a 0 value and a 1 value may mean a change in marital status when the two observations refer to the same person, but may simply represent a difference in marital status that has been true throughout the study period when the two observations refer to two different people. -logit- does not distinguish between-person and within-person comparisons. This is why -logit- is usually not used for analysis of longitudinal data. Other commands would be needed for that purpose.

              To confirm, dydx(*) first computes the change in union (DV) as collgrad changes (IV), holding all other variables constant (never_mar, grade, and age) constant. Then it separately computes the change in union (DV) as never_mar changes (IV) holding all other variables constant (collgrad, grade, and age). And continues with this process until the AMEs for all predictors in model are independently computed while holding the other predictors constant?
              Correct.

              Is it accurate to say that dydx(*) is computing the AME of each predictor, holding all other predictors at their actual value (asobserved)?
              Yes, for the command shown. -margins- has an -at()- option that permits you to hold other predictors constant at some value other than their observed value. -mtable- has an -at()- option, so I assume that -mtable- does the same. But if no -at()- or -atmeans- (which is an abbreviation for a more complicated -at()- option) option is specified, then, yes, all other predictors are held at their observed values.

              Again, let me emphasize that in answering the above I am making the assumption that -mtable- simply passes things through -margins- and organizes the results into tables. This is, I think, a highly plausible assumption, but I do not know it for a fact.

              My understanding for our conversation is it is not possible to get an AME of an interaction.
              It's more than that. The AME of an interaction isn't just somehow impossible to get. It doesn't exist; there is no such thing. It is "not possible to get" in the same sense that it is not possible to get a unicorn.

              Is there another solution to achieve what I am attempting?
              All you need is:
              Code:
              logit union i.nev_mar##i.collgrad grade age
              margins collgrad, dydx(nev_mar)
              margins collgrad, dydx(nev_mar) pwcompare
              The first -margins- command will show you the AMEs of nev_mar among the college grads and non-college grads separately. The second one will give you test statistics for the difference between those two AMEs. But they will not be output in a single table. I would be willing to bet moderate amounts of money that they can somehow be combined into a single table using the -collect- commands. But I do not -collect- well enough to suggest how. There are several other Forum members who are very capable working with -collect- and perhaps one of them will show us how it might be done.







              Comment

              Working...
              X