X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=octave_packages%2Feconometrics-1.0.8%2Fgmm_example.m;fp=octave_packages%2Feconometrics-1.0.8%2Fgmm_example.m;h=5825ae84f06983166d3f0c856b2db3fe24eb27b0;hb=c880e8788dfc484bf23ce13fa2787f2c6bca4863;hp=0000000000000000000000000000000000000000;hpb=1705066eceaaea976f010f669ce8e972f3734b05;p=CreaPhase.git diff --git a/octave_packages/econometrics-1.0.8/gmm_example.m b/octave_packages/econometrics-1.0.8/gmm_example.m new file mode 100644 index 0000000..5825ae8 --- /dev/null +++ b/octave_packages/econometrics-1.0.8/gmm_example.m @@ -0,0 +1,64 @@ +# Copyright (C) 2003,2004, 2005 Michael Creel +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; If not, see . + +# GMM example file, shows initial consistent estimator, +# estimation of efficient weight, and second round +# efficient estimator + + +n = 1000; +k = 5; + +x = [ones(n,1) randn(n,k-1)]; +w = [x, rand(n,1)]; +theta_true = ones(k,1); +lambda = exp(x*theta_true); +y = poissrnd(lambda); +[xs, scalecoef] = scale_data(x); + +# The arguments for gmm_estimate +theta = zeros(k,1); +data = [y xs w]; +weight = eye(columns(w)); +moments = "poisson_moments"; +momentargs = {k}; # needed to know where x ends and w starts + +# additional args for gmm_results +names = char("theta1", "theta2", "theta3", "theta4", "theta5"); +gmmtitle = "Poisson GMM trial"; +control = {100,0,1,1}; + + +# initial consistent estimate: only used to get efficient weight matrix, no screen output +[theta, obj_value, convergence] = gmm_estimate(theta, data, weight, moments, momentargs, control); + +# efficient weight matrix +# this method is valid when moments are not autocorrelated +# the user is reponsible to properly estimate the efficient weight +m = feval(moments, theta, data, momentargs); +weight = inverse(cov(m)); + +# second round efficient estimator +gmm_results(theta, data, weight, moments, momentargs, names, gmmtitle, scalecoef, control); +printf("\nThe true parameter values used to generate the data:\n"); +prettyprint(theta_true, names, "value"); + +# Example doing estimation in parallel on a cluster (requires MPITB) +# uncomment the following if you have MPITB installed +# nslaves = 1; +# theta = zeros(k,1); +# nslaves = 1; +# title = "GMM estimation done in parallel"; +# gmm_results(theta, data, weight, moments, momentargs, names, gmmtitle, scalecoef, control, nslaves);