Announcement

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

  • Marginal Effects of Quadratic terms

    Hello All,

    I'm running a regression with quadratic terms, and I'd like to graphically see the marginal effects that the explanatory variables have on my dependent variable. The code looks like this:

    Code:
    xtreg DepVar c.Var1##c.Var1 c.Var2##c.Var2 controls, re robust
    An excerpt of the data is found below, where the car is the dependent variable and the next two columns are the explanatory variables:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(car dcci dgei)
     .006094572  -.04854369  -.04368925
     .012289982   -.6504854  -.38349515
      .06451058  .014563024  -.02912617
    -.020245453   .04368925  .009708762
     .027952485  -.12440193 -.019138753
      .15572175   .54761904     .354067
      -.0610842   -.0333333  -.05263162
       .0403212   .06161141   .03317535
      .03867084  .028436065   .04265404
     .015166337   -.7535545   -.4739337
    -.017820526    .3744075   .28436017
    -.037084136 -.004739404  .014217973
    -.002426952  -.05687201  .004739404
      .03104728  -.08653843  -.10576928
     .018293347  .014423072   .01923084
     .000480968   -.2259615  -.11057699
     .014685898 -.024038434  -.06730765
    .0000147832  -.10576928  -.07692307
     .007311615  .033653915  .019230783
     -.06690646  -.04326928      -.0625
    end

    I basically need the graphs to illustrate the type of relationship between the variables.

    I'd appreciate any help.

    Best wishes,
    Henry

  • #2
    Henry: Take a look at help margins generate (this is an undocumented option for margins). I'm not sure this is exactly what you're asking, but this has proven useful to me in contexts that seem related.

    Comment


    • #3
      So, first you have to pick out interesting, relevant values of var1 and var2, values that span (or nearly span) the range of values, though perhaps excluding oddball outliers. Let's say, for sake of illustration, the interesting values of var1 are 1 through 10, and interesting values of var2 are 30 through 40. Then, you could do the following after your regression:

      Code:
      margins, at(var1 = (1(1)10) var2 = (30(1)40))
      marginsplot
      Or if you want a clearer separation of the effects of var1 and var2, you can do something like
      Code:
      margins, at(var1 = (1(1)10)) atmeans
      marginsplot
      You can rerun these interchanging the roles of var1 and var2.

      Note also that -marginsplot- must always be run immediately after -margins- (which entails re-running -margins- for each plot you want to get). Also note that -marginsplot- accepts most -graph twoway- options, so you can customize the appearance of these graphs to your taste.

      Comment


      • #4
        Thank you to both!

        Clyde,

        I need some clarification: the first code would show the relationship between var1 and var2 or is it both variables against the dependent variable? - I'm mainly interested in looking at each variable independently, i.e. how var1 behaves with respect to cumulative abnormal returns (which is the dependent variable). Would the second code fulfill that objective?

        Comment


        • #5
          The second code sounds like it is what you want. It will show how the dependent variable relates to var1, with var2 and any other covariates held at their mean value. This will give you a sense of the pure dependent variable:var1 relationship.

          Comment


          • #6
            Thank you, Clyde.

            I do have a follow up question about the difference in interpretation for "predictive margins" holding all other covariates at their mean value and "the average marginal effects"

            My simplified model looks like:
            Code:
            reg car c.CreditorProtection##c.CreditorProtection language
            car = continuous variable
            CP = continuous variable
            Language = categorical variable

            Based on our previous exchange predictive margins as shown in the code below reflect the pure relationship between car and CP,
            Code:
             
             margins, at(CreditorProtection = (-10(1)10)) atmeans marginsplot
            On the other hand, if I use the marginal effect function as follows:

            Code:
            margins, dydx(CreditorProtection) at(Creditor Protection=(-10(1)10))
            marginsplot
            How can I interpret the results on the latter? And would that code be applicable to seeing the marginal effects of a categorical variable, say language? - how would the interpretation change?

            I'm basically confused on the interpretation of predictive margins and marginal effects when the dependent variable is continuous and the explanatory variables include continuous and categorical variables.

            Thanks in advance for your support.

            Henry

            Comment


            • #7
              So, predictive margins are just expected values of the outcome variable (car in your case). And as you can see from the output of your first -margins- command, the expected outcome is a quadratic function of creditor protection. (If it doesn't look like that in the graph, then it means that the turning point of the parabola lies outside the range of values of creditor protection you have plotted.) Creditor protection being a continuous variable, its marginal effect is simply, in calculus terms, the first derivative of that function: d car/c creditor protection. Otherwise stated, it is the rate at which car increases per unit increase in creditor protection. That, too, as you can see from your second -margins- output, is a function of creditor protection, but this time it is a linear one. If the graph is an upsloping line it means that at higher levels of creditor protection, the effect of creditor protection on car increases. If it is a downloping line, it means that at higher levels of creditor protection the effect of creditor protection on car decreases.

              It is also possible to calculate marginal effects of discrete variables. For simplicity, let me assume that language takes only two values, and that they are coded 0 and 1. Then the marginal effect of language is defined as the difference between the expected value of car with language = 1 and the expected value of car with language = 0. And in calculating it, you do not need an -at()- option for the value of language. You just write -margins, dydx(language)-. (You can still specify -at()- options for other variables, or -atmeans- for other variables if that is what you need. But no -at(language = ...)- option is needed, nor appropriate.


              Comment


              • #8
                Awesome! That makes things clear. Thanks a lot

                Comment

                Working...
                X