{"schemaVersion":2,"courseId":"gmm","module":{"id":"gmm-moments","title":"1 · Moment conditions","summary":"GMM turns 'what we know about the population' into equations the data must satisfy, then minimizes how far the sample violates them.","stages":[{"type":"read","title":"From assumptions to equations","html":"<h2>The one big idea</h2><p>Almost every estimator you know secretly says: <em>there is some quantity in the population that should equal zero.</em> GMM makes that statement the centerpiece.</p><p>A <strong>moment condition</strong> is a population statement of the form</p><p class=\"katexish\">E[ g(data, θ) ] = 0</p><p>where θ is the parameter we want and <code>g</code> is a function we choose because we believe its expectation is zero <em>at the true θ</em>. The vector <code>g</code> is called the <strong>moment function</strong>.</p><h3>The simplest example: a mean</h3><p>Suppose we want the population mean μ of a variable x. The defining property of the mean is that deviations average to zero:</p><p class=\"katexish\">E[ x − μ ] = 0</p><p>Here θ = μ and g(x, μ) = x − μ. That single equation <em>is</em> the model.</p><h3>From population to sample</h3><p>We cannot compute E[·], but we can compute its sample analog — the average over our n data points. Define the <strong>sample moment</strong>:</p><p class=\"katexish\">ḡ(θ) = (1/n) Σᵢ g(xᵢ, θ)</p><p>The <strong>method of moments</strong> simply sets ḡ(θ) = 0 and solves. For the mean, (1/n)Σ(xᵢ − μ) = 0 gives μ̂ = x̄. We just re-derived the sample average from a moment condition.</p><div class=\"callout\"><b>Key idea.</b> A moment condition is a promise: \"at the true parameter, this thing averages to zero.\" Estimation = find the θ that makes the <em>sample</em> version as close to zero as possible.</div>","id":"gmm-moments-01","skillIds":["gmm.moment-conditions"],"estimatedMinutes":6,"difficulty":"advanced","prerequisiteStageIds":[]},{"type":"read","title":"When you have more equations than unknowns","html":"<h2>Just-identified vs over-identified</h2><p>Count things. Let θ have <strong>k</strong> parameters and let g produce <strong>m</strong> moment equations.</p><ul><li><strong>m = k (just-identified):</strong> as many equations as unknowns. You can usually solve ḡ(θ) = 0 exactly, hitting zero on the nose.</li><li><strong>m &gt; k (over-identified):</strong> more equations than unknowns. In general <em>no</em> θ sets all of ḡ to zero simultaneously — the equations disagree slightly because of sampling noise.</li><li><strong>m &lt; k (under-identified):</strong> too few equations; θ is not pinned down. Not usable.</li></ul><p>The over-identified case is where GMM earns its name. We can't make every moment zero, so instead we make them <em>collectively small</em>. We minimize a weighted sum of squared moments:</p><p class=\"katexish\">θ̂ = argmin<sub>θ</sub>  ḡ(θ)′ · W · ḡ(θ)</p><p>where <strong>W</strong> is a positive-definite <strong>weighting matrix</strong> that says how much each moment (and each combination of moments) matters. This scalar quantity is the <strong>GMM objective</strong>.</p><div class=\"callout\"><b>Key idea.</b> When m = k the choice of W is irrelevant (the minimum is exactly zero). When m &gt; k, W matters — and choosing it well is the whole game in Module 4.</div><p>Notice this nests the method of moments: if you <em>can</em> drive ḡ to zero, then ḡ′Wḡ = 0 for any W, so the GMM solution coincides with the exact solution.</p>","id":"gmm-moments-02","skillIds":["gmm.gmm-identification"],"estimatedMinutes":6,"difficulty":"advanced","prerequisiteStageIds":["gmm-moments-01"]},{"type":"code","title":"Hand-roll GMM for a mean","note":"Estimate μ from the single moment E[x−μ]=0 by literally minimizing the GMM objective with scipy. With one moment and one parameter (m=k=1) the objective is driven to zero and μ̂ equals the sample mean.","code":"import numpy as np\nfrom scipy.optimize import minimize\n\nrng = np.random.default_rng(0)\nn = 400\nx = rng.normal(5.0, 2.0, n)   # true mean 5\n\n# moment function g(x, mu) = x - mu  ->  sample moment is its average\ndef gbar(mu):\n    return np.array([np.mean(x - mu)])\n\n# GMM objective  J(mu) = gbar' W gbar,  here W = 1 (scalar, m=1)\ndef objective(p):\n    g = gbar(p[0])\n    return float(g @ g)\n\nres = minimize(objective, x0=[0.0])\nmu_hat = res.x[0]\n\nprint(f'sample mean x̄        = {x.mean():.6f}')\nprint(f'GMM μ̂ (minimizer)    = {mu_hat:.6f}')\nprint(f'objective at optimum  = {objective([mu_hat]):.3e}  (≈ 0, just-identified)')\nprint(f'gbar at optimum       = {gbar(mu_hat)[0]:.3e}')","id":"gmm-moments-03","skillIds":["gmm.moment-conditions"],"estimatedMinutes":10,"difficulty":"advanced","prerequisiteStageIds":["gmm-moments-02"]},{"type":"interactive","title":"Watch the GMM objective J(μ)","note":"The objective ḡ(μ)′ḡ(μ) is a parabola in μ that bottoms out exactly at the sample mean. Drag the candidate μ and read off J. The orange marker is your guess; the dashed line is where J is minimized (the sample mean).","params":[{"name":"mu","label":"Candidate μ","min":0,"max":10,"step":0.1,"value":2}],"template":"import numpy as np, matplotlib.pyplot as plt\nrng = np.random.default_rng(0)\nn = 400\nx = rng.normal(5.0, 2.0, n)\ndef J(mu):\n    g = np.mean(x - mu)\n    return g*g\ngrid = np.linspace(0,10,200)\nvals = [J(m) for m in grid]\nmu_star = x.mean()\nmu = {{mu}}\nplt.figure(figsize=(6,3.7))\nplt.plot(grid, vals, color='#af983f', lw=2, label='J(μ)=ḡ(μ)²')\nplt.axvline(mu_star, color='#6f6b57', ls='--', lw=1.5, label=f'min at x̄={mu_star:.2f}')\nplt.scatter([mu],[J(mu)], color='#da9100', s=70, zorder=5, label='your μ')\nplt.xlabel('candidate μ'); plt.ylabel('GMM objective J')\nplt.legend(fontsize=8)\nplt.title(f'μ={mu:.2f}  →  J={J(mu):.4f}   (min J at μ={mu_star:.2f})')","id":"gmm-moments-04","skillIds":["gmm.gmm-identification"],"estimatedMinutes":8,"difficulty":"advanced","prerequisiteStageIds":["gmm-moments-03"]},{"type":"quiz","title":"Check: counting moments","prompt":"You have a model with 2 parameters and you write down 5 moment conditions. This model is:","choices":["under-identified, so GMM cannot be used","just-identified, so the weighting matrix is irrelevant","over-identified, so GMM minimizes a weighted sum of moments and W matters","exactly-identified only if the moments are independent"],"answer":2,"hint":"Compare m (number of moments) with k (number of parameters).","explain":"With m = 5 moments and k = 2 parameters, m > k: the model is over-identified. You generally can't zero out all moments at once, so GMM minimizes ḡ′Wḡ and the choice of W changes the estimate.","id":"gmm-moments-05","skillIds":["gmm.moment-conditions"],"estimatedMinutes":5,"difficulty":"advanced","prerequisiteStageIds":["gmm-moments-04"],"variantId":"gmm-moments-05-core"},{"type":"quiz","title":"Check: what is a moment condition?","prompt":"The moment condition E[x − μ] = 0 is used to estimate μ. What does the sample analog (1/n)Σ(xᵢ − μ̂) = 0 give you?","choices":["the sample variance","the sample mean x̄","the median of x","an arbitrary value depending on W"],"answer":1,"hint":"Solve (1/n)Σ(xᵢ − μ̂) = 0 for μ̂.","explain":"Setting the sample moment to zero gives Σxᵢ = nμ̂, i.e. μ̂ = x̄. The method-of-moments estimator of the mean is just the sample average.","id":"gmm-moments-06","skillIds":["gmm.gmm-identification"],"estimatedMinutes":5,"difficulty":"advanced","prerequisiteStageIds":["gmm-moments-05"],"variantId":"gmm-moments-06-core"},{"type":"fillblank","title":"Counting the surplus","prompt":"When you write down <b>more</b> moment conditions than parameters (m &gt; k), the model is said to be ___.","lead":"You just saw a model with 5 moment conditions for 2 parameters — there are more equations than unknowns.","accept":["over-identified","overidentified","over identified","over-id","overid","over- identified"],"hint":"It's the opposite of 'just-identified' (m = k). The prefix means you have a surplus.","explain":"<b>The 'extra moments are wasted' instinct, named:</b> a model with m &gt; k is <b>over-identified</b>, and those surplus moments are not wasted — they give you a testable restriction (the J-test) and, if valid, extra efficiency. The tempting belief is that you should always reduce to m = k so every moment binds exactly; that throws away the over-identifying information. <b>Boundary:</b> exactly m = k is <em>just-identified</em> (moments hit zero exactly, W is irrelevant); m &lt; k is <em>under-identified</em> and not estimable.","points":15,"id":"gmm-moments-07","skillIds":["gmm.moment-conditions"],"estimatedMinutes":4,"difficulty":"advanced","prerequisiteStageIds":["gmm-moments-06"],"variantId":"gmm-moments-07-core"},{"type":"numeric","title":"How many over-identifying restrictions?","prompt":"A GMM model has m = 5 moment conditions and k = 2 parameters. How many over-identifying restrictions does it have? (enter a whole number)","answer":3,"tol":0.5,"hint":"Over-identifying restrictions = surplus moments = m − k.","explain":"<b>The 'restrictions = number of moments' trap:</b> the count of over-identifying restrictions is m − k = 5 − 2 = <b>3</b>, not 5. The tempting answer 5 counts <em>all</em> moments; but k of them are 'spent' pinning down the k parameters, leaving only m − k as independent checks. <b>Boundary:</b> when m = k the count is 0 — a just-identified model has nothing left over to test, which is exactly why no J-test exists there.","points":20,"id":"gmm-moments-08","skillIds":["gmm.gmm-identification"],"estimatedMinutes":5,"difficulty":"advanced","prerequisiteStageIds":["gmm-moments-07"],"variantId":"gmm-moments-08-core"}]}}
