Diff of /inst/gmm_results.m [000000] .. [afe5a1] Maximize Restore

  Switch to unified view

a b/inst/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, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
# usage: [theta, V, obj_value] = 
18
#  gmm_results(theta, data, weight, moments, momentargs, names, title, unscale, control, nslaves)
19
#
20
# inputs:
21
#      theta: column vector initial parameters
22
#       data: data matrix
23
#     weight: the GMM weight matrix
24
#    moments: name of function computes the moments
25
#             (should return nXg matrix of contributions)
26
# momentargs: (cell) additional inputs needed to compute moments.
27
#             May be empty ("")
28
#      names: vector of parameter names
29
#             e.g., names = str2mat("param1", "param2");
30
#      title: string, describes model estimated
31
#    unscale: (optional) cell that holds means and std. dev. of data
32
#             (see scale_data) 
33
#    control: (optional) BFGS or SA controls (see bfgsmin and samin). May be empty (""). 
34
#    nslaves: (optional) number of slaves if executed in parallel
35
#             (requires MPITB)
36
#
37
# outputs:
38
# theta: GMM estimated parameters
39
# V: estimate of covariance of parameters. Assumes the weight matrix
40
#    is optimal (inverse of covariance of moments)
41
# obj_value: the value of the GMM objective function
42
#
43
# please type "gmm_example" while in octave to see an example
44
45
46
function [theta, V, obj_value] = gmm_results(theta, data, weight, moments, momentargs, names, title, unscale, control, nslaves)
47
  
48
  if nargin < 10 nslaves = 0; endif # serial by default
49
  
50
  if nargin < 9
51
      [theta, obj_value, convergence] = gmm_estimate(theta, data, weight, moments, momentargs, "", nslaves);
52
  else
53
      [theta, obj_value, convergence] = gmm_estimate(theta, data, weight, moments, momentargs, control, nslaves);
54
  endif
55
56
57
  m = feval(moments, theta, data, momentargs); # find out how many obsns. we have
58
  n = rows(m);
59
60
  if convergence == 1
61
      convergence="Normal convergence";
62
  else
63
      convergence="No convergence";
64
  endif   
65
  
66
  V = gmm_variance(theta, data, weight, moments, momentargs);
67
68
  # unscale results if argument has been passed
69
  # this puts coefficients into scale corresponding to the original data
70
  if nargin > 7 
71
      if iscell(unscale)
72
          [theta, V] = unscale_parameters(theta, V, unscale);
73
      endif
74
  endif
75
76
  [theta, V] = delta_method("parameterize", theta, {data, moments, momentargs}, V);           
77
78
  n = rows(data);
79
  k = rows(theta);
80
  se = sqrt(diag(V));
81
  
82
  printf("\n\n******************************************************\n");
83
  disp(title);
84
  printf("\nGMM Estimation Results\n");
85
  printf("BFGS convergence: %s\n", convergence);
86
  printf("\nObjective function value: %f\n", obj_value);
87
  printf("Observations: %d\n", n);
88
89
  junk = "X^2 test";
90
  df = rows(weight) - rows(theta);
91
  if df > 0
92
      clabels = str2mat("Value","df","p-value");
93
      a = [n*obj_value, df, 1 - chisquare_cdf(n*obj_value, df)];
94
      printf("\n");
95
      prettyprint(a, junk, clabels);
96
  else
97
      disp("\nExactly identified, no spec. test");
98
  end;    
99
100
  # results for parameters                
101
  a =[theta, se, theta./se, 2 - 2*normal_cdf(abs(theta ./ se))];
102
  clabels = str2mat("estimate", "st. err", "t-stat", "p-value");
103
  printf("\n");
104
  prettyprint(a, names, clabels);
105
  
106
  printf("******************************************************\n");
107
endfunction