GmmEst: Generalized Methods of Moments Estimation

Description Usage Arguments Details Value References Examples

View source: R/GmmEst.R

Description

Function to estimate a parameter vector by one-step, two-step or iterative GMM

Usage

1
2
3
4
5
6
7
8
GmmEst(func, theta0, data,
    est_type=c("2step","1step","iter"), 
    func_jac=NULL, initial_W=NULL, 
    crit=10e-7, itermax=100, 
    optim_method=c("BFGS","Nelder-Mead","L-BFGS-B"),
    control = GmmEst_control(...), ...)

GmmEst_control(maxit = 5000, ...)

Arguments

func

a user supplied function of the form f(theta,data), with the first input being a vector of the parameters, which are to be estimated. The function is assumed to return a (nobs x kmoms) matrix of moments.

theta0

a vector of initial values of the parameters.

data

a dataframe or matrix containing the necessary data to compute the moments in func.

est_type

Optional: one of 2step, 1step or iter. Default value is 2step.

func_jac

Optional: a user supplied function of the form j(theta,data), with the first input being a vector of the parameters which are to be estimated. The function is assumed to return the expected / average jacobian of the moment conditions. Should be matrix of size (kmoms x kparam).

initial_W

Optional: an initial weighting matrix of class matrix that can be supplied by the user. If not supplied, the identity matrix is used.

crit

Optional: the stopping rule for the iterative GMM. It can be reduce to increase the precision.

itermax

Optional: the maximal number of iterations in the iterated GMM procedure.

optim_method

Optional: the possible implemented methods in optim that are used to minimize the objective function. Default is BFGS.

control, maxit

Optional: a list of control parameters passed to optim. maxit defines the maximal number of iterations in optim.

...

further arguments that can be passed to optim.

Details

Please have a look into the vignette for

Value

An object of class "GmmEst".

The object of class "gmm" is a list containing at least:

coefficients

(kparams by 1) vector of coefficients.

jstat

a list with elements value and pval returning the value of the J-Statistic (overidentification test). If the model is overidentified, the corresponding p-value is included, otherwise it is set to NA.

nobs

number of observations.

vcov

variance-covariance matrix of the estimated parameters.

kparams

number of estimated parameters.

kmoms

number of moment conditions.

est_type

string of the applied estimation type.

S

the estimated S matrix

W

the inverse of the S matrix.

dmat

the d-matrix.

gt

an (nobs by kmoms) matrix of moment condition, based on the estimated parameters.

gt_mean

the (kmoms by 1) vector of moment condition, based on the estimated parameters.

niter

If est_type=='iter', the number of performed GMM iterations.

vcov_gt

The variance-covariance matrix of the moment condition matrix

identification

String that shows if the model is over-, just-, or underidentified.

References

Cochrane, J.H. (2005), Asset Pricing. Revised edition. Princeton University Press

Greene, W.H. (2011), Econometric Analysis. 7. edition. Prentice Hall.

Hall, A.R. (2005), Generalized Method of Moments. 1. edition. Oxford University Press.

Hansen, L.P. (1982), Large Sample Properties of Generalized Method of Moments Estimators. Econometrica, 50, 1029-1054,

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# ====================================
# A minimal example: GMM can do OLS.

# Load data
data(mtcars)

## User specified function
func = function(params, data){
  b0 = params[1]
  b1 = params[2]
  
  y = data$mpg
  x = data$hp
  
  yfit = b0 + b1*x
  eps = y - yfit
  
  gt1 = eps
  gt2 = eps*x
  
  gt = cbind(gt1, gt2)
  return(gt)
}

# Estimation
mod = GmmEst(func, c(20,0), mtcars)

# Print result
summary(mod)


# ====================================
# Second example: Consumption based Asset pricing model

# Load dataset from within the package
data("data_consumption",package = "GmmEst")

# Define user specific function FUNC 
# (moment conditions using rmrf and hml portfolio returns as instruments)
mom_cond = function(params, data){
  gamma = params[1]
  
  beta = 1
  dc = data$dc
  rmrf = data$rmrf
  hml = data$hml
  rf = data$rf
  
  gt1 = beta*dc^(-gamma)*rmrf
  gt2 = beta*dc^(-gamma)*hml
  gt = cbind(gt1, gt2)
  return(gt)
}

# Define FUNC_JAC (in this case the gradient of the moment conditions)
mom_cond_grad = function(params,data){
  gamma = params[1]
  
  beta = 1
  dc = data$dc
  rmrf = data$rmrf
  hml = data$hml
  
  d1 = -dc^(-gamma)*log(dc)*rmrf*beta
  d2 = -dc^(-gamma)*log(dc)*hml*beta
  d = c(mean(d1),mean(d2))
  return(d)
}

# Estimate the gamma parameter
mod2 = GmmEst(mom_cond, 100, data, est_type = "2step", 
             optim_method = 'BFGS', func_jac = mom_cond_grad)
summary(mod2)

GmmEst documentation built on May 2, 2019, 6:30 p.m.