Announcement

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

  • Does margins, dydx() work like this?

    Dear Statalisters:

    I've been playing around with -margins- lately, and I am using the dydx options for the first time. I think I know how dydx works, but I'm not sure.

    Let's say I run a regression and then calculate out the marginal effect using dydx:
    Code:
    regress y age i.female i.race
    margins, dydx (age female)
    Where female is a dummy variable and age is continuous, and race is three categories (White, Black, Other). My understanding in this case is that it calculates out the average effect size for age and female over the sample when you increase x by 1, which is the same as the coefficient.

    If I were to then add a polynomial term, so that:
    Code:
    regress y c.age##c.age i.female i.race
    margins, dydx (age female)
    My understanding is that this would give me the average effect size for age just like before, but this time it would the average effect size for both age and age-squared when you increase age by 1. This is where I stop being able to verify things easily just by looking at the output, since the marginal effect for age is now split across two variables.

    Now let's say I want to compare black respondents to white and "other" respondents:
    Code:
    regress y c.age##c.age##i.race
    margins, dydx (age), over(black)
    So now "black" is a dummy variable where black==0 is race==1 & race==3. My understanding is that I would now get two average effect sizes. The one for black==1 would be the average effect size over race==2 when age increases by 1, and would take into account both the nonlinearities of the squared age term but also . Meanwhile, the black==0 would be the average effect size of an increase of 1 for age among race==1 & race==3 . My understanding is that this average effect for black==0 would be due to both the coefficients for all the interactions with i.race, but also the size of the subpopulation of race==1 vs race==3.

    Do I have this correct so far? Or am I off?

    Thanks so much for your time,
    Jonathan

  • #2
    Your descriptions of what these -margins- commands leave out some detail. For the first two situations, what you write is basically correct, because the omitted details do not matter.

    Just be careful with the last situation. The omitted details matter here.
    Code:
    regress y c.age##c.age##i.race
    margins, dydx (age), over(black)
    can be done, but it may or may not give you what you actually want. When you separate the data into groups using the -over()- option, the marginal effects calculated are conditional on the value of the -over()- variable and there is no adjustment for differences in the distribution of other variables. In your specific case, this means that if, in your data, the age distributions of blacks and non-blacks differ, this approach will give you results that do not adjust for that age difference. Now, that may be fine for your purposes. But if what you need is marginal effects that are adjusted for age differences between blacks and non-blacks you would have to do it differently:
    Code:
    regress y c.age##c.age##i.black
    margins black, dydx(age)
    This would give you separate estimates for the average marginal effect of age for blacks and non-blacks, and these estimates would be adjusted for any difference in the black and non-black age distributions.

    Comment


    • #3
      Thanks--this is the type of explanation I needed! It sounds like the first one is a story about coefficients and the relative size of white vs. other, while the second one is a story about the coefficients and the age distribution of black vs. non-black. Both are marginal effects, but tells us more about the coefficients and the other one tells us more about a specific prediction in the population.

      Comment

      Working...
      X