Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Creel committed Apr 27, 2024
1 parent 053f7c7 commit 9cdd4fb
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 19 deletions.
19 changes: 19 additions & 0 deletions Examples/GMM/GMMcriterion.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# this shows how the GMM criterions combines information from two
# moment conditions.
using Plots

weight_on_first = 1 # play with this to see the effect

# the two separate moment conditions
m1(θ) = 2 + 3θ
m2(θ) = 5 -3θ + 0.1*θ^2

# the GMM criterions
m(θ) = [m1(θ), m2(θ)]
W = 0.05*[weight_on_first 0. ; 0. 1.]
s(θ) = dot(m(θ),W,m(θ))[1]

# plot it
plot([m1,m2,s], labels=["m¹ₙ(θ)" "m²ₙ(θ)" "sₙ(θ) "], title="Two moment conditions, and the GMM criterion")

savefig("gmmcriterion.png")
Binary file added Examples/GMM/gmmcriterion.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
168 changes: 150 additions & 18 deletions econometrics.lyx
Original file line number Diff line number Diff line change
Expand Up @@ -37432,7 +37432,16 @@ In both cases,
\begin_inset Formula $E(y|\boldsymbol{x})=\lambda=\exp(\mathbf{x}'\beta)$
\end_inset

,
and the density is parameterized as
\begin_inset Formula $f_{Y}(y|\boldsymbol{x},\theta)$
\end_inset

where
\begin_inset Formula $\theta=(\beta,\alpha)$
\end_inset

.
\end_layout

\end_deeper
Expand Down Expand Up @@ -39635,6 +39644,41 @@ literal "true"
\end_inset


\end_layout

\begin_layout Itemize
The GMM estimator is a consistent and asymptotically normal estimator that does not require such strong assumptions as does the ML estimator.
\end_layout

\begin_layout Itemize
Many widely used estimators,
such as instrumental variables estimators,
least squares estimators,
and maximum likelihood,
can be put into the form of GMM estimators
\end_layout

\begin_layout Itemize
thus,
the study of the theory for GMM can be applied in many cases
\end_layout

\begin_layout Itemize
GMM theory can be a simpler way to formulate theory than some of the original presentations.

\end_layout

\begin_layout Itemize
,
it is a convenient and relatively simple way to think of things,
and it has wide application.
\end_layout

\begin_layout Standard
\begin_inset Newpage newpage
\end_inset


\end_layout

\begin_layout Section
Expand Down Expand Up @@ -40316,11 +40360,11 @@ where
\end_inset

with
\begin_inset Formula $\mathcal{E}\bar{m}_{n}(Z_{n},\theta_{0})=0,$
\begin_inset Formula $E\bar{m}(Z_{n},\theta_{0})=0,$
\end_inset


\begin_inset Formula $\mathcal{E}\bar{m}_{n}(Z_{n},\theta)=0$
\begin_inset Formula $E\bar{m}(Z_{n},\theta)\ne0$
\end_inset

,
Expand All @@ -40346,18 +40390,28 @@ and

.

\end_layout

\begin_layout Standard
\begin_inset Newpage newpage
\end_inset


\end_layout

\begin_layout Standard
Usually,
the moment conditions will be averages of terms:

\begin_inset Formula $\bar{m}_{n}(\theta)=\frac{1}{n}\sum_{t=1}^{n}m(Z_{t},\theta)$
\begin_inset Formula
\begin{align*}
\bar{m}_{n}(\theta) & =\frac{1}{n}\sum_{t=1}^{n}m(Z_{t},\theta)\\
& \equiv\frac{1}{n}\sum_{t=1}^{n}m_{t}(\theta)
\end{align*}

\end_inset

.
In this case the moment contributions
\begin_inset Formula $m(Z_{t},\theta)$
In this case the moment contributions
\begin_inset Formula $m_{t}(\theta)\equiv m(Z_{t},\theta)$
\end_inset

are a
Expand All @@ -40370,19 +40424,22 @@ Usually,
\end_inset

with
\begin_inset Formula $Em(Z_{t},\theta_{0})=0,$
\begin_inset Formula
\[
Em_{t}(\theta_{0})=0,
\]

\end_inset

and
\begin_inset Formula
\[
Em_{t}(\theta)\ne0,\forall\theta\ne\theta_{0}.
\]

\begin_inset Formula $Em(Z_{t},\theta)\ne0$
\end_inset

,

\begin_inset Formula $\forall\theta\ne\theta_{0}$
\end_inset

.
\begin_inset Newpage newpage
\end_inset

Expand Down Expand Up @@ -40526,7 +40583,11 @@ nolink "false"
This will be the case if our moment conditions are correctly specified.
With this,
it is clear that the minimum of the limiting objective function occurs at the true parameter value.
The only assumption that warrants additional comment is that of identification.

\end_layout

\begin_layout Itemize
The only assumption that warrants additional comment is that of identification.
In Theorem
\begin_inset CommandInset ref
LatexCommand ref
Expand Down Expand Up @@ -40563,7 +40624,11 @@ i.e.,
\begin_inset Formula $\forall\theta\neq\theta_{0}.$
\end_inset

Taking the case of a quadratic objective function

\end_layout

\begin_layout Itemize
Taking the case of a quadratic objective function
\begin_inset Formula $s_{n}(\theta)=\bar{m}_{n}(\theta)^{\prime}W_{n}\bar{m}_{n}(\theta),$
\end_inset

Expand All @@ -40574,6 +40639,7 @@ i.e.,

\end_layout

\begin_deeper
\begin_layout Itemize
Applying a uniform law of large numbers,
we get
Expand All @@ -40596,6 +40662,7 @@ Since

\end_layout

\end_deeper
\begin_layout Itemize
Since
\begin_inset Formula $s_{\infty}(\theta_{0})=m_{\infty}(\theta_{0})^{\prime}W_{\infty}m_{\infty}(\theta_{0})=0,$
Expand Down Expand Up @@ -40908,6 +40975,18 @@ D_{n}(\theta)\equiv\frac{\partial}{\partial\theta}\bar{m}_{n}^{\prime}\left(\the
\end_inset

but it is omitted to unclutter the notation).
\end_layout

\begin_layout Standard

\color blue
This is the gradient vector.
To get the GMM estimator,
set these equal to zero,
and solve.
\end_layout

\begin_layout Standard
\begin_inset Newpage newpage
\end_inset

Expand Down Expand Up @@ -41162,7 +41241,19 @@ nolink "false"
\end_inset

,
and noting that the scores have mean zero at
and noting that the scores (in eq.

\begin_inset CommandInset ref
LatexCommand ref
reference "gmmscores"
plural "false"
caps "false"
noprefix "false"
nolink "false"

\end_inset

) have mean zero at
\begin_inset Formula $\theta_{0}$
\end_inset

Expand Down Expand Up @@ -41530,6 +41621,47 @@ status open
Choosing the weighting matrix
\end_layout

\begin_layout Standard
The following figure shows how the GMM criterion function,

\begin_inset Formula $s_{n}(\theta)$
\end_inset

combines information from two moment conditions.
The place where the green line minimizes is between the places where the red and blue lines have their roots.
Play around with
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
href{./Examples/GMM/GMMcriterion.jl}{GMM/GMMcriterion.jl}
\end_layout

\end_inset

to see how changing the weight matrix changes the GMM criterion.
\end_layout

\begin_layout Standard
\begin_inset Graphics
filename Examples/GMM/gmmcriterion.png
width 15cm

\end_inset


\end_layout

\begin_layout Standard
\begin_inset Newpage newpage
\end_inset


\end_layout

\begin_layout Standard
\begin_inset Formula $W$
\end_inset
Expand Down
Binary file modified econometrics.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion src/GMM/gmm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function gmm(moments, θ, weight)
θhat, objvalue, converged = fminunc(obj, θ)
# derivative of average moments
D = try
ForwardDiff.jacobian(m, vec(θhat))'
ForwardDiff.jacobian(m, vec(θhat))' # jacobian get ∂m/∂θ', but D is the transpose
catch
Calculus.jacobian(m, vec(θhat), :central)'
end
Expand Down
1 change: 1 addition & 0 deletions src/GMM/gmmresults.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function gmmresults()
return
end

# do 2-step if weight provided, otherwise, do CUE with NW cov.
function gmmresults(moments, θ, weight="", title="", names="", efficient=true)
n,g = size(moments(θ))
CUE = false
Expand Down

0 comments on commit 9cdd4fb

Please sign in to comment.