Average marginal effects by hand? I'm having trouble calculating average marginal effects by hand. I have the coefficients from Latent Gold (so if anyone knows how to get AMEs from that program, that would be helpful!).
Otherwise, I have a spreadsheet with the coefficients from the logit output, but I'm not sure how to calculate the average marginal effect by hand.
I've seen several sites (i.e. Calculate Marginal effect by hand (without using packages or Stata or R) with logit and dummy variables) that indicate that the formula is:
$$p(y=1)*p(y=0)*\beta$$.
Say I'm interested in the average marginal effect of years of education on the outcome. Is $p(y=1)$ calculated by plugging in the mean of all the variables, including education, into the logit equation? And then multiplying by $\beta$ education? Or do I calculate $p(y=1)$ without holding education at it's mean, since it's the coefficient of interest?
Thanks so much!
 A: The marginal effect of $X$ for a unit $i$ is the change in the probability of the event if you were to change $X$ by a very small amount from its value for unit $i$ while keeping all other covariates that the same value for unit $i$. That is, it's the change in probability if you were to change $X$ by a very small amount but not change anything else (measured) about that unit.
The average marginal effect of $X$ is the average of the marginal effects of $X$ across all units in the sample. It's not the marginal effect at the mean, which is what you would get if you were to plug in the means of all the covariates into the logit function to calculate $p(y=1|X=\bar x)$, as you suggested.
You need to calculate $p(y_i=1|X=x_i)$ and $p(y_i=0|X=x_i) = 1- p(y_i=1|X=x_i)$ for every unit $i$ in your sample, then compute the average of $p(y_i=1|X=x_i)\times p(y_i=0|X=x_i)$ across all units, and multiply that average by $\beta$. This is the average marginal effect of the (continuous) predictor with coefficient $\beta$ (note the procedure is different for binary predictors). In a formula, this would be:
$$
\beta \frac{1}{N} \sum^N_{i=1} p(y_i=1|X=x_i) \times p(y_i=0|X=x_i)
$$
To do this manually, one unit at a time, compute their $p(y_i=1|X=x_i)$ and $p(y_i=0|X=x_i)$ by plugging in their values of $X$ (i.e., the covariates, including the focal covariate, e.g., education) into the logistic equation with the estimated coefficients. Do this for all units. Then take the average of $p(y_i=1|X=x_i) \times p(y_i=0|X=x_i)$ and multiply that average by the coefficient $\beta$ for the focal covariate. You can get the average marginal effect for other continuous covariates simply by substituting the corresponding $\beta$.
