# Delta Method for Marginal Effects of Generalized Linear model

Consider the generalized regression model (in my case a probit, but I'll leave it more generally):

$$E[y|X] = F(x'\beta)$$

where both $x$ and $\beta$ are ($K \times 1$) column vectors and $F$ is some function (in my case a c.d.f, and we call its derivative $f$). We can easily derivate the marginal effects as:

$$\frac{\partial E[y|X]}{\partial x} = f(x'\beta)\beta$$

And for notation simplicity let us define this marginal effects function as function of our estimates: $$\underbrace{g(\hat{\beta})}_{f: R^K \rightarrow R^K} \equiv f(x'\hat{\beta})\hat{\beta}$$

The Delta method allows us to find the variance of $g(.)$. If we define $J_g$ as the Jacobian Matrix of g, we know that:

$$Var \left( g(\hat{\beta}) \right) = J_g' \Omega_{\hat{\beta}} J_g \quad \quad where \ \ \Omega_{\hat{\beta}} = Var(\hat{\beta}).$$ Fine. My question comes here. We are treating $g$ as a function of $\beta$, but it actually also depends on a vector of observations $x_i$, meaning that this will be a different function for each observation $i$ given its $x_i$. So we could write for each individual $i$:

$$Var \left( g_i(\hat{\beta}) \right) = J_{g_i}' \Omega_{\hat{\beta}} J_{g_i}$$

Usually we compute the Average Marginal Effect:

$$AME = \frac{1}{N} \sum_{i=1}^N g_i(\hat{\beta})$$

And what I would do to find the variance for this marginal effect (and Im not sure about that) is

$$Var(AME) = Var \left( \frac{1}{N} \sum_{i=1}^N g_i(\hat{\beta}) \right)$$

which, under independence between individuals, simplifies to

$$Var(AME) = \frac{1}{N^2} \sum_{i=1}^N Var \left( g_i(\hat{\beta}) \right)$$

However, the Stata software usually do something else (here pg 324 and here post number 4), which (as far as I understood) was computing the "average Jacobian" by calculating each individual-specific jacobian, summing them, and dividing by the number of observations.

I would like to know (a) whether my suggestion in this post is wrong (I admit I might be loosing something, specially by passing the variance inside the summation) and (b) why the computation of the "mean" of the jacobian provides the correct estimation for the variance of the Average Marginal Effects.

What i gather from this is that we want the variance of the Average Marginal Effect (AME) and hence our transformed function is the AME: $$g(\hat{\beta}) = AME = \frac{1}{N} \sum_{i=1}^N g_i(x_i,\hat{\beta})$$ Then using the delta method we have $$Var \left( g(\hat{\beta}) \right) = J_g' \Omega_{\hat{\beta}} J_g \quad \quad where \ \ \Omega_{\hat{\beta}} = Var(\hat{\beta})$$ and $$J_g' = \frac{\partial\left[\frac{1}{N}\sum_{i=1}^N g (x_i,\hat{\beta})\right]}{\partial \hat\beta} = \frac{1}{N}{\left[\sum_{i=1}^N \frac{\partial \left (g (x_i,\hat{\beta})\right)}{\partial \hat\beta}\right]}$$