Description Usage Arguments Details Value References Examples
Function to estimate a parameter vector by one-step, two-step or iterative GMM
1 2 3 4 5 6 7 8 |
func |
a user supplied |
theta0 |
a vector of initial values of the parameters. |
data |
a dataframe or matrix containing the necessary data to compute the moments in |
est_type |
Optional: one of 2step, 1step or iter. Default value is 2step. |
func_jac |
Optional: a user supplied |
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 |
control, maxit |
Optional: a list of control parameters passed to |
... |
further arguments that can be passed to |
Please have a look into the vignette for
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 |
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 |
vcov_gt |
The variance-covariance matrix of the moment condition matrix |
identification |
String that shows if the model is over-, just-, or underidentified. |
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,
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.