Announcement

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

  • Margnis Error - at values for factor sex do not sum to 1

    Dear Statalisters,

    I am estimating a binary model and I want to obtain the marginal effects of a continuous variable holding fixed a categorical variable.

    Let me explain along the lines of an example. In the example below I would be interested in knowing the average marginal effect of one additional year of age, conditional on being male or female, on having a heart attack.

    webuse nhanes2, clear
    logit heartatk i.sex#c.age bmi

    So I think I should type something like:
    margins age, at(sex=0)

    However, this gives me the error mentioned in the subject.

    If I turn the problem around and estimate the marginal effect of gender at a certain age (as found in many online examples) everything works out fine (command used: margins sex, at(age=50)), but this is not the outcome I am interested in....


    I guess I need to add some special syntax to account for the fact that sex is a categorical variable, however, so far I was not able to figure out the right solution.

    Best Stefan

  • #2
    I'm not entirely clear about what you're trying to do here, but let me point out several problems that may or may not get at your concerns:

    1. The -logit- model you proposed includes an interaction but no corresponding main effects. That's typically not a reasonable model specification, though there are exceptions.

    2. I'm not sure what margins, at (sex = 0) would get you given that in the nhanes2 data set the coding for sex is 1 and 2.

    3. If you want the sex-specific marginal effects of a unit increase in age, then I think the command you need is -margins sex, dydx(age)-

    Hope this helps.

    Comment


    • #3
      Great, number 3. Solves my problem, thank you.

      Concerning number 1, I don't follow, as the two commands below, with the first one including main effects and the second one not, are perfect substitutes.
      logit heartatk i.sex#c.age age bmi
      logit heartatk i.sex#c.age bmi

      Comment


      • #4
        Yes, but neither of your models gives the exact same result as

        logit heartatk i.sex##c.age bmi

        i.e. your models leave out a main effect of sex. In this case it doesn't matter a lot but it could in others. In general, if you have higher order terms (interactions, squared terms) you should include the lower level terms used to compute them.
        -------------------------------------------
        Richard Williams, Notre Dame Dept of Sociology
        StataNow Version: 19.5 MP (2 processor)

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

        Comment


        • #5
          Now I see. I agree, the example was definitively too minimalistic...

          Comment

          Working...
          X