The sample moments

The GMM estimation requires a user supplied function that calculates the sample moments and their first derivatives. This is of extreme importance since it drives all the aspects of the GMM estimation. This section describes the syntax and use of this function.


Suppose that you want to create a function, called myfunction, that calculates the sample moments and their derivative.

SYNTAX

[mom, der] = myfunction(theta, data, additional argument)

INPUTS

The function requires the following inputs:
The parameters (denoted by theta)
The dataset used for estimation (denoted by data)
Any additional arguments your estimation requires (denoted by additional argument).

The name that you give to your inputs can be whatever you like. The only things that matter are
1. The inputs must be provided in the same order as above, and
2.Size of inputs
theta: A Px1 column vector, where P is the number of parametrs you want to estimate.
data: A TxK matrix, where T is the number of observations, and K is the number of variables in your dataset.
additional argument:
This is required ONLY if your moments are using instruments
. In this case, this must be a TxQ matrix, where T is the number of observations, and Q is the number of instruments.
In the case that your sample moments are not using instruments, you don't have to provide this argument - i.e. your function can be of the form myfunction(theta, data).

OUTPUT

Note that the output consists of two arguments:
The sample moments, defined as mom
The first derivative of the sample moments, defined as der
The names that you give in the output arguments can be whatever you like. The only things that matter are
1. The inputs must be provided in the same order as above, and
2. Size of output arguments
mom: A TxM matrix, where T is the number of observations, and M is the number of moments. In other words, the i-j element of this matrix is the value of the jth moment condition, evaluated at the ith observation.
der: An MxP matrix, where M is the number of moments, and P is the number of the parameters of interest. This is the Jacobian of the sample moments; the i-j element is the derivative of the ith sample moments, with respect to the jth parameter.

NOTE

Some of you may wonder why mom has to be a TxM vector, and not a sample average, similarly to the case of der ; after all, the GMM minimand is based on the sample moment condition!
The reason is that the calculation of the long run variance of the moments requires the whole vector of the moments, not just their average. As a result, the sample moments must be provided in that way and not as a sample average.

EXAMPLE

Have a look on the file cbapm.m that resides in the GMM toolbox folder. This function calculates the moment conditions and their gradient for the Consumption Based Asset Procing Model, as it was studied by Harvey and Singleton (1982).