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
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
Comment