What are the "moment conditions" in the GMM method? Also: GMM vs IV vs 2SLS?

I keep seeing talk of 'moment conditions' or 'moment equations', but don't exactly understand the context.

Consider a very standard regression model: $$y_i = \beta x_i + u_i$$

where $$u_i$$ is an error term, and suppose all the classic linear regression assumptions hold.

If I relax the exogeneity assumption,i.e., $$\mathbb{E}(u|x) \neq 0$$ (also side question: Why does this imply that $$\mathbb{E}(u_i x_i)\neq0$$?), then using OLS here will produce biased estimates right?

Is $$\mathbb{E}(u_i | x_i)=0$$ the 'moment condition' in OLS? Is it $$\mathbb{E}(u_i x_i) =0$$ ?

My second question is whether GMM, 2SLS, and IV are specifically distinct from one another.

My book says that when we have $$K$$ endogeneous regressors and $$K$$ instruments (exactly identified) we use IV.

In the case of being over-identified, and we have $$J>K$$ IVs, we use GMM. What about for the under-identified case?

Finally, What's the best way to distinguish between these different methods? For instance, what is the difference in using GMM in an over-identified case vs trying to use IV in that case?

Thanks for any help.

The moment condition is the exogeneity condition $$\mathbb{E}(u_i x_i) = 0$$. ($$\mathbb{E}(u_i | x_i)=0$$ is not a moment condition. It is an equality of random variables.)

OLS is a special case of Method of Moments estimator where the estimates are given by the sample analogue of a population moment condition. For OLS, the sample analogue of $$\mathbb{E}(u_i x_i) = 0$$ is $$\sum e_i x_i = 0,$$ where $$e_i = y_i - \hat{\beta} x_i$$. This sample condition characterizes $$\hat{\beta}$$.

As the terminology suggests, GMM is a generalization of method of moments. IV estimator is a special case of GMM, where the moment condition is $$\mathbb{E}(u_i z_i) = 0$$ with $$z_i$$ being a vector of IV's. (For OLS, $$z_i = x_i$$. Exogenous regressors are examples of instruments.)

When system is over-identified, the sample version of $$\mathbb{E}(u_i z_i) = 0$$ need not have a solution. Therefore one minimizes an appropriate quadratic form instead---this is what makes GMM "generalized", compared to MM.

Strictly speaking, 2SLS is an algorithm that implements the IV estimator, rather than an estimator. Trivially you can find other equivalent algorithms that implements IV. This slight abuse of terminology is, however, standard.

GMM is, of course, not restricted to IV. See for example, Hansen's seminal application of GMM on the equity premium puzzle.

It does not make sense to speak of estimation for under-identified models---they are unidentified.