1 # Copyright (C) 2003,2004,2005 Michael Creel <michael.creel@uab.es>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; If not, see <http://www.gnu.org/licenses/>.
16 # usage: [theta, V, obj_value] =
17 # gmm_results(theta, data, weight, moments, momentargs, names, title, unscale, control, nslaves)
20 # theta: column vector initial parameters
22 # weight: the GMM weight matrix
23 # moments: name of function computes the moments
24 # (should return nXg matrix of contributions)
25 # momentargs: (cell) additional inputs needed to compute moments.
27 # names: vector of parameter names
28 # e.g., names = char("param1", "param2");
29 # title: string, describes model estimated
30 # unscale: (optional) cell that holds means and std. dev. of data
32 # control: (optional) BFGS or SA controls (see bfgsmin and samin). May be empty ("").
33 # nslaves: (optional) number of slaves if executed in parallel
37 # theta: GMM estimated parameters
38 # V: estimate of covariance of parameters. Assumes the weight matrix
39 # is optimal (inverse of covariance of moments)
40 # obj_value: the value of the GMM objective function
42 # please type "gmm_example" while in octave to see an example
45 function [theta, V, obj_value] = gmm_results(theta, data, weight, moments, momentargs, names, title, unscale, control, nslaves)
47 if nargin < 10 nslaves = 0; endif # serial by default
50 [theta, obj_value, convergence] = gmm_estimate(theta, data, weight, moments, momentargs, "", nslaves);
52 [theta, obj_value, convergence] = gmm_estimate(theta, data, weight, moments, momentargs, control, nslaves);
56 m = feval(moments, theta, data, momentargs); # find out how many obsns. we have
60 convergence="Normal convergence";
62 convergence="No convergence";
65 V = gmm_variance(theta, data, weight, moments, momentargs);
67 # unscale results if argument has been passed
68 # this puts coefficients into scale corresponding to the original data
71 [theta, V] = unscale_parameters(theta, V, unscale);
75 [theta, V] = delta_method("parameterize", theta, {data, moments, momentargs}, V);
80 printf("\n\n******************************************************\n");
82 printf("\nGMM Estimation Results\n");
83 printf("BFGS convergence: %s\n", convergence);
84 printf("\nObjective function value: %f\n", obj_value);
85 printf("Observations: %d\n", n);
90 clabels = char("Value","df","p-value");
91 a = [n*obj_value, df, 1 - chi2cdf(n*obj_value, df)];
93 prettyprint(a, junk, clabels);
95 disp("\nExactly identified, no spec. test");
98 # results for parameters
99 a =[theta, se, theta./se, 2 - 2*normcdf(abs(theta ./ se))];
100 clabels = char("estimate", "st. err", "t-stat", "p-value");
102 prettyprint(a, names, clabels);
104 printf("******************************************************\n");