ZoltanRacz / MomentMatching.jl

This is a package to estimate parameters of macroeconomic models by moment matching methods, such as GMM or SMM.
MIT License
1 stars 0 forks source link

MomentMatching

Build Status codecov

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.

Routine files

There are three files which are not model-specific and which are used in all applications:

  1. _SMM_GMMestimation: contains structures and functions to perform the estimation;
  2. _SMM_GMMinference: contains functions to perform inference and diagnostics;
  3. _SMM_GMMoutput: contains structures and functions to produce tables and figures to display the estimation results.

1. SMM_GMM_estimation

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.

2. SMM_GMM_inference

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}$.

3. SMM_GMM_output

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:

Model-specific files

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):

In addition, the following can also be model-specific:

To do (not very urgent)

Other comments

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.