GOALS 

This tutorial covers the use of user-defined moment equations with gmmFit. After this tutorial, you should be able to:

  • Define a moment function
  • Use a custom moment function to estimate a linear model
  • Use a custom moment function to estimate an instrumental variables model
  • Estimate a model with multiple moment equations

 

THE MOMENT EQUATION 

The gmmFit procedure requires a pointer to a user-specified moment procedure as an input. There are several concepts to keep in mind when creating your moment procedure:

  • Procedures are created in GAUSS by placing commands to be executed between the proc statement and endp statement.
  • Values are returned from a function using the retp statement.
  • Moment procedures must have the parameter vectors as the first input, a data matrix as a second input and must have a single return.

All moment procedures should take the general form:

 

//Procedure definition for moment equation
 proc (1) = meqn(b, yt, ...);

…

retp(g);
 endp;

 

Note: The ... indicates that the moment equation may accept a flexible number of inputs following the first data matrix input. These inputs will be passed untouched from the gmmFit procedure (in the order they are input) to the moment equation.

 

ESTIMATING A LINEAR MODEL 

Consider the case of a linear model:

  • The moments for this model are given by E[xtut(θ0)] = 0E[xtut(θ0)] = 0 with ut(θ0) = yt−βtxt
  • This inputs for this equation will include the parameter vector, b, the dependent variable matrix, yt, and the independent variable matrix, xt.

 

 //Procedure definition for moment equation
 proc (1) = meqn(b, yt, xt);

local ut, dt;

/** OLS resids **/
 ut = yt - b[1] - b[2]*xt[., 2] - b[3]*xt[., 3];

/** Moment conditions **/
 dt = ut.*xt;

retp(dt);

endp;

 

The corresponding call to gmmFit takes a pointer to the moment equation, meqn, as the first input, followed by the y and x matrices.

 

 //Perform estimation
 call gmmFit(&meqn, y, x, gctl);

 

Note: The final input to gmmFit above, gctl, is a gmmControl structure, which will be discussed in the next tutorial.

 

© 2024 Aptech Systems, Inc. All rights reserved.

ESTIMATING AN INSTRUMENTAL VARIABLES MODEL

Now suppose that we suspect that there is an issue with endogenous variables and wish to use instrumental variables:

  • The moments for this model are given by E[zut(θ0)]=0 with ut(θ0)=yt−βtxt
  • This inputs for this equation now include the parameter vector, b, the dependent variable matrix, yt, the independent variable matrix, xt, and the instruments matrix,zt.

 

 //Procedure definition for moment equation
 proc (1) = meqn(b, yt, xt, zt);

local ut, dt;

/** OLS residuals **/
 ut = yt - b[1] - b[2]*xt[., 2] - b[3]*xt[., 3];

/** Moment conditions **/
 dt = ut.*zt;

retp(dt);

endp;

 

The corresponding call to gmmFit again includes a pointer to the moment equation meqn but this time must also include the inputs yx, and z.

 

 //Perform estimation
 call gmmFit(&meqn, y, x, z, gctl);

 

USING MULTIPLE MOMENTS 

Finally, let’s consider the case where we wish to include multiple moment equations. For this example, we will estimate the degrees of freedom of a t-distribution is the second and fourth moments :

  • The moments for this model are given by  and  .
  • This inputs for this equation include just the parameter vector, b, the dependent variable matrix, yt. No additional inputs are required.
  • When multiple moments are included, they must be concatenated together and returned as a single output from the moment equation.

 

 //Procedure definition for moment equation
 proc(1) = meqn(b, yt);

local g1, g2;

g1 = yt.^2 - b/(b-2);
 g2 = yt.^4 - (3*b^2)/((b-2)*(b-4));

retp(g1~g2);

endp;

 

The corresponding call to gmmFit includes a pointer to the moment equation meqn and y.

 

 //Perform estimation
 call gmmFit(&meqn, y);

 

CONCLUSION 

Congratulations! You have:

  • Defined a moment equation for use in the gmmFit procedure.
  • Created a custom moment equation to estimate a linear model.
  • Created a custom moment function to estimate an instrumental variables model.
  • Estimated a model with multiple moment equations.

The next tutorial describes the model control settings available in the gmmControl structure.