Announcement

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

  • Marginal effects for logit with interaction terms

    Hi guys,

    I ran a logit regression which includes some interaction terms. I did create those interaction terms before the logit command. Now I would like to get the marginal effects for the estimated coefficients. What is the best way to obtain the marginal effects in this case?
    What command should I use?

    Thank you very much.

    Regards,
    Benny

    P.S.:
    margins, dydx(*) noatlegend

    reveals missing values only for dy/dx and non-estimatable standard errors
    Last edited by Benny Miller; 25 Apr 2015, 03:03.

  • #2
    Benny,

    Interaction terms in non-linear models are tricky to interpret. Especially the marginal effects you want are likely to be biased.
    Maarten Buis wrote a very good article about that in the Stata Journal :
    http://www.stata-journal.com/sjpdf.h...iclenum=st0194
    I advice you to take a look on that.

    But a quick answer to your question would thus be : Don't try to compute marginals effects, but rather focus on the odds ratio (i.e. launch the logit with the ,or option)
    Charlie

    Comment


    • #3
      Benny:
      it is difficult (for me, at least) to advise without seeing what you typed and what Stata gave you back (as per FAQ).
      That said, as a general rule, it is better to create interactions using -fvvarlist-.
      Kind regards,
      Carlo
      (Stata 18.0 SE)

      Comment


      • #4
        Adding to what Carlo says, had you used factor variable notation in your regression instead of creating your own interaction variables, you could get these marginal effects with a simple invocation of the -margins- command. Unless your model took many many hours to converge, it is worth your while to do it over rather than struggle with hand-calculating marginal effects.

        Comment


        • #5
          Hello,

          Currently I am estimating a model with a very similar setting. I got a binary dependent variable (y) and multiple independent variables. I create two versions of my model one with two independent factor variables of interest (x1 & x2) and their interaction (x1x2) and the other with a independent factor variable (x1) and an independent continous variable (x3) (values: 0, 45, 46, 58, 105, 176, 246, 1508) and their interaction (x1x3).

          I estimated them in the two different manners (creating the interaction beforehand and creating the interaction in the model itself using #)

          gen x1x2=(x1*x2)
          gen x1x3=(x1*x3)
          1. svy: logit y i.x1i.i. x2 i.x1x2
          2. svy: logit y i.x1 c.x3 c.x1x3


          3. svy: logit y i.x1 i.x2 i.x1#i.x2
          4. svy: logit y i.x1 c.x3 i.x1#c.x3


          As I am trying to estimate the effect those variables and their interactions have on the probability on y=1 I relied on the command:

          margins, dydx(*) vce(unconditional)

          I have read multiple articles (e.g. Maarten Buis) on this issue but until now could not really find a solution on how to determine the correct way to estimate the marginal effects. As far as I understood margins command should show me the wanted marginal effects for model 1 and 3 as all dependent variables are binary variables and coded with a factor i.. So the margins, dydx(*) tells me how much the probability of y=1 changes if x1, x2 or x1x2 change by one uni (0 to 1).

          My bigger issue now lies with the marginal effects of model 2 and 4. Again the margins, dydx(*) command should give me the change in probability of y=1 for a discrete change in x1 (0 to 1) and also the change in probability of y=1 for a one-step change in x2 (continous). As this continuous variable only consists of the values listed above this results in seemingly wrong marginal effects (way too large).

          Could you tell me which approach would be more suitable in general for the estimation of marginal effects (pre-calculation of interaction effects (binary-binary; binary-continous) VS in-model-calculation of interaction effects using #, i., c.)?

          As I am also looking for the marginal effect of the interaction term the method of using # to create interaction terms results in the margins, dydx(*) command not supplying me with any marginal effect for this interaction term (as described by Williams (2012) already).

          Thank you very much for any advice you could give me.
          Kind regards
          Caspar

          Comment


          • #6
            I believe approaches 3 and 4, which really entirely on factor variable notation, are correct. With the first 2 approaches the interrelationships between x1, x2, and x3 will not be known to stata.

            You say "As this continuous variable only consists of the values listed above this results in seemingly wrong marginal effects (way too large)." Well, without seeing the actual output, I can't address your concern.

            At least the way Stata does things, there is no marginal effect for an interaction term. See Vince Wiggins discussion at

            https://www.stata.com/statalist/arch.../msg00293.html

            I'm not sure why Williams (2012) would lead you to think interaction terms would have marginal effects. You may want to look at

            https://www3.nd.edu/~rwilliam/xsoc73994/Margins01.pdf

            Also, I find marginal effects for continuous variables hard to understand. I much prefer the approach taken by Royston's mcp command:

            https://www3.nd.edu/~rwilliam/xsoc73994/Margins03.pdf
            -------------------------------------------
            Richard Williams, Notre Dame Dept of Sociology
            Stata Version: 17.0 MP (2 processor)

            EMAIL: [email protected]
            WWW: https://www3.nd.edu/~rwilliam

            Comment


            • #7
              Dear Prof. Williams,

              Thank you very much for your quick reply. I understood from your literature that Stata does not calculate the marginal effects of interaction terms and this makes sense to me. If I understood your correctly you advise to make use of the -mcp- command for continous variables. I will try this out now.

              In case of my interaction effects of interest how would you go on now? I have one binary variable indicating whether the individual lives in an affected state (x1=0/1) and one binary variable indicating whether the individual observation stems from prior or post the period of interest (x2(post2009)=0/1). I would include these two variables with an i. in my regression to specify them as factor/binary variables. If i now want to find the effect of living in an affected state post 2009 (interaction effect= x1*x2) which strategy should I employ in order to find this "marginal" effect? As this effect is the main effect of interest I would need some way to judge about it although - as you already mentioned- Stata itself does not supply me with this marginal effect of an interaction effect. This binary interaction effect is of interest to me to estimate the extensive effect in both a svy: reg estimation (continous dependent variable) and a svy: logit estimatio (binary dependent variable).

              The second part of my analysis wiould like to estimate the intensive effect so I make use of the same binary variable (x1=0/1) and a continous variable (x3= 0-1508). Again here I would like to know the effect that one additional value of x3 (terror attack in my case) in the affected area (x1=1) (interaction effect=x1*x3) has on the dependent variables in a svy:reg model (conitnous dependent variable) and in a svy: logit model (binary dependent variable).

              By now I am a bit confused whether I can show the effect of the interaction term at all or not and which command I shall use to generate the estimators of interest (binary and continous independent variables, binary and continuous interaction terms).

              Thank you very much in advance for any help you could supply me with.
              Greetings

              Example: :
              svy: regress agefirstunionCM i.BH c.attacknumberCM i.BH#c.attacknumberCM i.surveystate

              This supplies me with the coefficient -0.064 for the interaction effect --> as one state faced 1.508 attacks this would mean the age at first marriage would be at -80 years old which is impossible
              Last edited by Cas Ziegler; 26 May 2020, 02:44.

              Comment


              • #8
                It doesn't make any sense to look at a 'marginal effect' of an interaction variable without also taking into account the main effect(s).

                You appear to want to look at outcome variable values given specific combinations of regressor variables. Have a look at the at() options for -margins- and related options

                Comment


                • #9
                  Dear Mr. Jenkins,

                  My ultimate goal would be to find the effect on extra attack in the affected states has on my dependent variables (binary and continous). It would be best to get this effect for a single attack instead than for a certain number of attacks (e.g. 20,200,1500) which would the margins, at() would supply me with if I am correct.
                  For your better understanding of my currently models here you will find pictures of my current models in their most basic form,

                  Click image for larger version

Name:	Statalist.JPG
Views:	1
Size:	49.3 KB
ID:	1555200

                  Click image for larger version

Name:	Statalist2.JPG
Views:	1
Size:	53.6 KB
ID:	1555201

                  Comment


                  • #10
                    Please do not post output as you have. (On my screen it is blurry, and cannot be copied and manipulated.) Please reread the Forum FAQ, and note the strong advice to post Stata output (and input) using CODE delimiters.

                    I don't understand your complaint in
                    It would be best to get this effect for a single attack instead than for a certain number of attacks (e.g. 20,200,1500) which would the margins, at() would supply me with if I am correct.
                    The numlist that you can feed into at() can be a single number, and that number could be 1 (if that makes any sense -- it doesn't to me). I suspect you want to see the difference in outcome associated with a change from (say) 200 to 201. Which can also be done. Etc. Etc.

                    -margins- is a very powerful command, but also complicated (as this thread indicates). It's hard to beat making the investment in reading the Manual entries through. And also all of Rich Williams's helpful documents.

                    [PS I'm out of here now.]

                    Comment


                    • #11
                      Like Stephen Jenkins , I am not sure if I follow you. However, I suspect you want to use either mcp or else margins with the at option. Why don't you check out the suggested options and come back if questions persist.

                      As for your claim that you are getting impossible results -- from the posted results, it looks to me like the effect of attacks is 0 for those in group 1 and .032 for those in group 0 (since the interaction term and the main effects of attacks are equal but opposite in sign). I am not sure how that yields an impossible result. If you are doing hand calculations you may be doing them wrong.

                      But, even if it is impossible, there is no reason that that can't happen. Perhaps the model is misspecified, e.g. you should use the log of attacks, or create splines. Attacks has a really weird distribution (values: 0, 45, 46, 58, 105, 176, 246, 1508) and its effects may not just be a simple linear function. Indeed, you may just want to treat it as a categorical variable rather than as a continuous one.
                      -------------------------------------------
                      Richard Williams, Notre Dame Dept of Sociology
                      Stata Version: 17.0 MP (2 processor)

                      EMAIL: [email protected]
                      WWW: https://www3.nd.edu/~rwilliam

                      Comment


                      • #12
                        Dear Prof. Williams,
                        I tried the margins and mcp commands now and also a few days ago and still struggled.
                        The distribution of attacknumberCM actually looks like this (0,1,2,3,4,5,6,8,9,11,17,32,45,46,58,105,176,246,1 .508). Question here would be - as yous suggested to generate a log value or categorical variables. Categorical variables would not work in my opinion as I would have colinerarity with state dummies (only one state has 1.508 attacks and for this state also a state dummy exists). All attacks took place and were summed up post2009 so in my model I differentiate between heavily affected states (BH=0/1) and then include the attacknumber(if observation pre2009 attacknumber = 0; if observation post2009 attacknumber = 0-1.508 attacks). The dummy BH in all models indicates whether a state can be identified as a heavily affected region or not (more than 40 attacks so 7states--> 45,46,58,105,176,246,1508).
                        Therefore in my extensive effect models the relevant variables are BH and post2009, in my intensive model they are BH and attacknumber.

                        So currently two issues persist:

                        1. In my logit models with a binary independent variables and an interaction effect as well as state dummes and controls Stata estimates logit results.
                        Code:
                        svy: logit childmarriage i.BH i.post2009CM i.post2009CM#i.BH i.muslim i.urban i.kanuri i.hhheadmale i.literacy i.wealthindex i.edulevel c.eduyears i.edulevelpartner c.eduyearspartner i.polygamoushh i.surveystate
                        As soon as I now command Stata to show me marginal effects
                        Code:
                        margins, dydx(*) vce(unconditional)
                        it supplies me with many estimates but states (not estimable) for the binary variable BH and all binary state dummies. For other binary variables such as muslim I do not have this issue. So far I could not figure out why this happens and could not find a solution in forums, publications etc.. Do you have any advice on how to deal with this/why this happens only for the BH and state dummies?

                        For example the following code again shows me non estimable for the margins
                        Code:
                        margins, dydx(post2009CM) vce(unconditional) at(BH=1) at(BH=0)
                        If I make use of the strategy suggested by Mr. Viggins (Stata) in 2013 (https://www.stata.com/statalist/arch.../msg00293.html) Stata also shows me (not testable) and I assume this is due to the non working of margins on my BH variable.
                        Code:
                        margins r.BH#r.post2009CM, vce(unconditional)



                        2. In my intensive effects models I am running following models:

                        Code:
                        svy: reg agefirstunionCM i.BH c.attacknumberCM c.attacknumberCM#i.BH i.muslim i.urban i.kanuri i.hhheadmale i.literacy i.wealthindex i.edulevel c.eduyears i.edulevelpartner c.eduyearspartner  i.largefamily i.polygamoushh i.surveystate
                        Code:
                        svy: reg agefirstbirthpregTP i.BH c.attacknumberTP c.attacknumberTP#i.BH i.muslim i.urban i.kanuri i.hhheadmale i.literacy i.wealthindex i.edulevel c.eduyears i.edulevelpartner c.eduyearspartner  i.largefamily i.polygamoushh i.surveystate
                        Code:
                        svy: logit childmarriage i.BH c.attacknumberCM c.attacknumberCM#i.BH i.muslim i.urban i.kanuri i.hhheadmale i.literacy i.wealthindex i.edulevel c.eduyears i.edulevelpartner c.eduyearspartner i.polygamoushh i.surveystate
                        Code:
                        svy: logit teenpreg i.BH c.attacknumberTP c.attacknumberTP #i.BH i.muslim i.urban i.kanuri i.hhheadmale i.literacy i.wealthindex i.edulevel c.eduyears i.edulevelpartner c.eduyearspartner i.polygamoushh i.surveystate
                        I get regression and logit results for all four models and now would like to determine what kind of effect an additional attack has on the age at childmarriage and age at teenage childbirth as well as on the probability to be married as child and becoming a teenage mother.

                        These are essentially my two bigger research questions (extensive, intensive) making use of four dependent variables (age at childmarriage, age at teenage childbirth, childmarriage (share/probability), teenage pregnancy (share(/probability).
                        I hope I could make clearer what my estimation is about and I would greatly appreciate any advice on how to proceed with these two "issues" in order to generate reliable results which I could interpret (such as marginal effects).
                        Thank you very much in advance!
                        Last edited by Cas Ziegler; 26 May 2020, 07:40.

                        Comment


                        • #13
                          Dear forum members,
                          I created a different Stata List post which also includes the Stata outputs regarding my issue with the non estimable outputs when running the above mentioned margins command.
                          https://www.statalist.org/forums/for...-not-estimable

                          Any help on my issues listed above (intensive effects, log of attacknumbers etc.) in this post here or on the other are highly appreciated and I thank you very much already for your valuable insights.

                          Kind regards

                          Comment


                          • #14
                            I should add that the binary indicator BH (0/1) depends on the surveystate - meaning if an individual woman lives in certain states (seven states to be exact) she is coded as BH=1 and if not (30 other states) she is coded as BH=0. Could this be the issue if I include the BH indicator (using i.BH) and state fixed effects (using i.surveystate) in my models and try margins command? (maybe because of colinearity etc?
                            If I use then suddenly all margins are presented
                            Code:
                            margins, dydx(*) vce unconditional noestimcheck
                            Last edited by Cas Ziegler; 27 May 2020, 05:34.

                            Comment

                            Working...
                            X