by Gualtiero Azzalini (Stockholm School of Economics)\ Zoltan Racz (Stockholm School of Economics)
Description. This package allows to perform Method of Moments estimation (Generalized and Simulated).
It comprises three files which are not model-specific and are used in all applications and model-specific files. See below for more details.
There are three files which are not model-specific and which are used in all applications:
This is the core file performing the estimation routine. To describe the procedure let's introduce some useful notation:
Note: identification requires $M \geq K$.
The estimation algorithm in the function estimation
includes a global and a local stage in its most general form. Nevertheless, the code is flexible enough to allow performing only one of the two stages at a time.
Global stage. In the global stage (see matchmom
) a Sobol sequence is generated on the parameter space defined by $\theta$. The objective function is evaluated at each combination of parameters in the sequence. If only the global stage is performed, the best (in terms of lowest value of the objective function) combination of parameters is returned as the minimizer. Else, the best points (the number can be specified by the user) are used as starting guesses for the local stage.
Note: it is important that the number of global points evaluated is large, so that all the areas of the parameter space are searched well enough. This is especially true if the objective function is not well behaved.
Local stage. The most promising candidates found in the global stage are then used as starting points for a local stage (see opt_loc!
), in which the Nelder-Mead algorithm is used to find the minimum of the objective function. If only the local stage is performed, the initial guess can be supplied by the user. The global minimizer is then the best point among the values returned at the end of the local minimization routine at each tried starting guess.
The file also contains a function two_stage_estimation
to perform two-step GMM estimation. In the first step estimation is performed with a default weighting matrix. Parametric bootstrap (described in the next section) then allows to get the updated efficient weighting matrix (under the assumption that the model and estimated parameters are correct). The latter is then used as weighting matrix for estimation in the second step.
This file contains functions to perform diagnostics and inference on the estimation results.
Diagnostics. In order to check that a minimum is achieved, the function marginal_fobj
evaluates the objective function at points around the estimated parameter $\hat{\theta}$ in one dimension at a time (see below for functions to plot this check) and saves the results in an array.
Parametric bootstrap. In order to gauge how precisely the targeted moments are estimated in the original data, a function param_bootstrap
to perform parametric bootstrap is provided. Specifically, assuming model and estimated parameters are correct, alternative samples are simulated - with the same size as the original sample data sample - and, for each sample, an alternative vector of moments to match is computed. Then, for every alternative moment vector, the estimation procedure (local stage) is repeated. The resulting distribution of estimated parameters can be used to obtain the bootstrap confidence intervals. To check that the chosen seed does not influence the results (in which case it is recommended to restart the whole estimation with bigger simulation sizes), this procedure can optionally be repeated with several seeds.
Standard errors. The asymptotic variance sandwich_matrix
of the parameter estimates has the usual sandwich form: $(G^\prime W G)^{-1} G^\prime W S W G(G^\prime W G)^{-1}$. $\hat{G}$ can is computed numerically at the estimated parameter value $\hat{\theta}$ with the function Qmatrix
. $W$ is the weighting matrix used in estimation. Under the assumptions of the parametric bootstrap, there are two sources of variation in the parameter estimates: variation in the simulated sample for a given seed and across seeds. The parametric bootstrap procedure just outlined returns a distribution of the parameter estimates that considers exactly these two factors. Thus, the covariance matrix of the simulated moments is a consistent estimator for $S$ and, after having been computed by the function Omega_boots
, it is used as $\hat{S}$.
Note: If the model is just identified or if $\hat{W}$ is a consistent estimator of $S^{-1}$ then the variance simplifies to $(G^\prime S^{-1} G)^{-1}$. The latter happens, for instance, when $\hat{W}$ is the efficient weighting matrix obtained in the two-stage estimation procedure or, in the parametric bootstrap case just described when $\hat{W}$ is set to the inverse of the consistent estimator of $S$.
J-test. A function Jtest
to test over-identifying restriction is provided. The $J$-statistic is defined as $n\hat{g}^{\prime}\hat{W}\hat{g}$ where $\hat{W}$ is a consistent estimator of $S^{-1}$, $\hat{g}$ a consistent estimator of the moment conditions and $n$ is the sample size. Under the null $J \rightarrow{d} \chi^2{M-K}$.
This file contains functions to organize the estimation results and to perform some sanity checks on them. More specifically, the following figures and tables can be generated:
fsanity
: figure plotting the estimated parameters in every trial of the global or local stage in increasing order with respect to the objective function value obtained. If the found optimum is stable, then the estimated parameter values should not vary much, especially for the trials that achieved objective function values close to the minimum.
fmarg
: figure plotting the how the objective function varies when marginally moving the estimated parameter in one dimension at a time. If the optimum is a minimum, then the graphs should show that the objective function is minimized at that point.
fbootstrap
: figure showing the histogram of parameter estimates obtained in each bootstrap iteration.
plotmoms
: figure comparing the moments in the data and in the model (at the estimated parameter values).
tableest
: table with parameter estimates, optionally including bootstrap SE.
tablemoms
: table comparing the moments in the data and in the model (at the estimated parameter values), optionally including bootstrap SE.
This section describes the general format for model-specific files so that they can be used by the files performing the estimation routine.
In general, the framework is flexible to accomodate any user-defined model. However, the following model-specific files should be included (as they are called in the general estimation routine):
EstimationMode
: type for model to be estimated.InnerAuxStructure
: type for the auxiliary structures to be initialized.defaultInnerAuxStructure
: sets up default auxiliary object for computing model moments.default_weight_matrix
: sets up default weighting matrix to compute the objective function.datamoments
: computes moments from the data.parambounds
: return parameter labels and ranges.obj_mom
: computes moments in model under a given parameter guess.mdiff
: computes deviation of model moments from data moments.momentnames
: returns the full names of the moments, used for organising results.mean_moments
: computes mean of moments, used for bootstrapping.In addition, the following can also be model-specific:
indexvector
: if the default of having all model parameters estimated should be changed.ftypemom
: if not having model-specific default moments to be estimated should be changed.plotmoms
: if the default of having an empty graph to compare moments in the model and data should be changed.estimation
or estimation_name
)moment_names
do we need two methods?Showing Progress: Currently we rely on https://github.com/timholy/ProgressMeter.jl. There seem to be some bugs related to show a messy output when combined with multithreading (maybe ok in mac?), e.g.
before registering, we should check the status of these issues.