Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.

# Re: st: margins dydx for logit model with interaction terms

 From Richard Williams To statalist@hsphsun2.harvard.edu, statalist@hsphsun2.harvard.edu Subject Re: st: margins dydx for logit model with interaction terms Date Thu, 09 Aug 2012 15:20:35 -0500

```At 11:30 AM 8/9/2012, David Quinn wrote:
```
```Hello,

I am estimating a logit model as such: Y=X1 + X2 + X3 + X4 + X1*X3 + X2*X3.
```
```
```
What was the actual logit command? Did you use factor variable notation? If not -margins- will assume x1 and x2 are continuous rather than dichotomous. Assuming you want to treat x3 as continuous, The command should be something like
```
logit y i.x1 i.x2 x3 x4 i.x1#c.x3 i.x2#c.x3

```
```X1 and X2 are binary predictors.  X3 is an ordinal predictor.  X4 is a
control variable.  X1*X3 and X2*X3 are the interaction of X1 and X2,
respectively, with X3.

I'd like to assess the discrete change in my dependent variable for X1
at different levels of X3, given that I expect there to be interaction
effects of X1 and X3.   I also need to set X2 and X2*X3 at zero while
doing this in order to calculate the proper discrete change of
interest.  As for the control variable X4, I'd like to just keep it at
its mean value.

I used the following margins command to calculate the discrete change in X1:

margins, dydx(X1) atmeans at(X3=(1 2 3) X1*X3=(1 2 3) X2=0 X2*X3=0)
```
```
if you have used factor variable notation, I think all you need is

margins, dydx(x1) atmeans at(x3=1 2 3) x2 = 0)

I could be wrong so make sure it looks right.

```
```"Atmeans" places X4 at its mean, while the stuff after "at" specifies
the specific values at which to hold the other variables while
calculating the change.

But in the legend that accompanies the results, it keeps saying that
X1 is being held at its mean value when the discrete change
calculations are being made.  Why does margins set the variable of
interest--located after the dydx command--to its mean value when
calculating the discrete change, when clearly one would want the dydx
calculations to be made at specific values of the variable of
interest?  I just assumed that placing the variable of interest after
dydx would tell Stata to calculate the change in Y as that variable
moves from zero to one, holding all other variables at the values
specified after "at."

Am I doing something incorrectly?

Perhaps I should just use King et al.'s CLARIFY package to calculate
the predicted probabilities, or perhaps even follow Buis' (2010)
advice and calculate the odds.  From what I gather, those two are a
bit more straightforward then using the margins command.

--Dave
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```
```
-------------------------------------------
Richard Williams, Notre Dame Dept of Sociology
OFFICE: (574)631-6668, (574)631-6463
HOME:   (574)289-5227
EMAIL:  Richard.A.Williams.5@ND.Edu
WWW:    http://www.nd.edu/~rwilliam

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```