]> Creatis software - CreaPhase.git/blob - octave_packages/econometrics-1.0.8/gmm_results.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / econometrics-1.0.8 / gmm_results.m
1 # Copyright (C) 2003,2004,2005  Michael Creel <michael.creel@uab.es>
2 #
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.
7 #
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.
12 #
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/>.
15
16 # usage: [theta, V, obj_value] =
17 #  gmm_results(theta, data, weight, moments, momentargs, names, title, unscale, control, nslaves)
18 #
19 # inputs:
20 #      theta: column vector initial parameters
21 #       data: data matrix
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.
26 #             May be empty ("")
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
31 #             (see scale_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
34 #             (requires MPITB)
35 #
36 # outputs:
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
41 #
42 # please type "gmm_example" while in octave to see an example
43
44
45 function [theta, V, obj_value] = gmm_results(theta, data, weight, moments, momentargs, names, title, unscale, control, nslaves)
46
47   if nargin < 10 nslaves = 0; endif # serial by default
48
49         if nargin < 9
50                 [theta, obj_value, convergence] = gmm_estimate(theta, data, weight, moments, momentargs, "", nslaves);
51         else
52                 [theta, obj_value, convergence] = gmm_estimate(theta, data, weight, moments, momentargs, control, nslaves);
53         endif
54
55
56         m = feval(moments, theta, data, momentargs); # find out how many obsns. we have
57         n = rows(m);
58
59         if convergence == 1
60                 convergence="Normal convergence";
61         else
62                 convergence="No convergence";
63         endif
64
65         V = gmm_variance(theta, data, weight, moments, momentargs);
66
67         # unscale results if argument has been passed
68         # this puts coefficients into scale corresponding to the original data
69         if nargin > 7
70                 if iscell(unscale)
71                         [theta, V] = unscale_parameters(theta, V, unscale);
72                 endif
73         endif
74
75         [theta, V] = delta_method("parameterize", theta, {data, moments, momentargs}, V);
76
77         k = rows(theta);
78         se = sqrt(diag(V));
79
80         printf("\n\n******************************************************\n");
81         disp(title);
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);
86
87         junk = "X^2 test";
88         df = n - k;
89         if df > 0
90                 clabels = char("Value","df","p-value");
91                 a = [n*obj_value, df, 1 - chi2cdf(n*obj_value, df)];
92                 printf("\n");
93                 prettyprint(a, junk, clabels);
94         else
95                 disp("\nExactly identified, no spec. test");
96         end;
97
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");
101         printf("\n");
102         prettyprint(a, names, clabels);
103
104         printf("******************************************************\n");
105 endfunction