# GMM Introduction

### Goals

This tutorial introduces the use of gmmFit and gmmFitIV to estimate GMM models. After this tutorial, you should be able to estimate a basic model using either:

as your data inputs.

## Basic usage with a formula string

The gmmFitIV procedure accepts dataset names and formula strings as direct inputs. This allows you to tell gmmFitIV which data to load, saving the extra step of manually loading your data into matrices. For example, consider using data from the dataset auto2.dta in gmmFitIV to fit the model:

$$mpg = \alpha + \beta * weight$$

// Create string with full path to dataset
dataset = getGAUSSHome() $+ "examples/auto2.dta"; // Estimate the model call gmmFitIV(dataset, "mpg ~ weight"); This code will produce the following output Generalized Method of Moments Valid cases: 74 Number of Moments: 0 Degrees of freedom: 72 Dependent Variable: mpg Number of Parameters: 2 Standard Prob Variable Estimate Error t-value >|t| ----------------------------------------------------- CONSTANT 39.440284 1.961267 20.110 0.000 weight -0.006009 0.000576 -10.429 0.000 Instruments: weight, Constant ## Basic usage with matrix inputs The gmmFitIV procedure can also accept matrix inputs. We demonstrate using the same model as before. However, this time we: 1. Load the variables mpg and weight from the auto2.dta dataset into a GAUSS matrix, data. 2. Create two separate data matrices mpg and weight. 3. Use the matrices mpg and weight as the dependent and independent variable inputs, respectively, in the gmmFitIV function call. // Create string with full path to dataset dataset = getGAUSSHome()$+ "examples/auto2.dta";

// Load specified variables into a GAUSS matrix.
data = loadd(dataset, "mpg + weight");

// Create separate column vectors for each variable.
// This step is not necessary but is shown for
// didactic purposes.
mpg = data[.,1];
weight = data[.,2];

// Estimate the model with matrix inputs
call gmmFitIV(mpg, weight);

This code will give us the same estimates as above but will use generic names for the variables, since GAUSS matrices do not store variable names.

Generalized Method of Moments

Valid cases:                                       74
Number of Moments:                                  0
Degrees of freedom:                                72
Dependent Variable:                                 Y
Number of Parameters:                               2

Standard                Prob
Variable     Estimate      Error     t-value     >|t|
-----------------------------------------------------------

Beta1       39.440284    1.961267    20.110     0.000
Beta2       -0.006009    0.000576   -10.429     0.000

Instruments:           Z1, Z2 

### Conclusion

This tutorial showed you how to estimate the parameters of a simple linear model using a dataset name and formula string or matrix inputs.

The next tutorial will demonstrate the use of gmmFit to estimate GMM models with user-specified moment procedures.

### Have a Specific Question?

Get a real answer from a real person

### Need Support?

Get help from our friendly experts.

### Try GAUSS for 14 days for FREE

See what GAUSS can do for your data