%GMMSTART  Front end for GMM estimation.
%          Gmmstart is a script file which contains the information
%          on the starting parameter vector and data.  It is a 
%          user-supplied routine.  See also GMM, GMMH, GMMHC, UNCMIN.
%

%          Ellen R. McGrattan, 3-27-89
%          Revised, 3-2-90

%          References:
%          ----------
%          [1]  Eichenbaum, Martin S. and Lars P. Hansen, ``Estimating
%               Models with Intertemporal Substitution Using Aggregate
%               Time Series Data,'' NBER Working Paper 2181, 1987.
%          [2]  Eichenbaum, Martin S. and Lars P. Hansen, ``Estimating
%               Models with Intertemporal Substitution Using Aggregate
%               Time Series Data,'' JOURNAL OF BUSINESS AND ECONOMIC
%               STATISTICS, 8:53-70, 1990.
%          [3]  Eichenbaum, Martin S., Lars P. Hansen, and Kenneth Singleton,
%               ``A Time Series Analysis of Representative Agent Models of
%               Consumption and Leisure Choice Under Uncertainty,'' NBER
%               Working Paper No. 1981, 1986.
%          [4]  Hansen, L.P. and K.J. Singleton, "Generalized Instrumental
%               Variables Estimation of Nonlinear Rational Expectations
%               Models," ECONOMETRICA, 50:1269-1286, 1982.
%          [5]  Hansen, Lars P., "Large-sample Moments Properties of
%               Generalized Method of Moments Estimators,'' ECONOMETRICA,
%               50:1029-1054, 1982.
%          [6]  Newey, W.K. and K.D. West, "A Simple, Positive Semi-
%               Definite, Heteroskedasticity and Autocorrelation Consistent
%               Covariance Matrix," ECONOMETRICA, 55:703-708, 1987.

clear

%-------------------------------------------------------------------------
%                             GLOBAL VARIABLES   
%-------------------------------------------------------------------------

global xgmm    zgmm        nobs         qgmm      Wgmm       mgmm     lgmm 
%       |       |           |            |         |          |        |  
%    x data  instrumental  # of         dimen.   weighting  dim. of   # of
%            variables,    observations of z(t)  matrix     function  params  
%            z(t)          t=1,... nobs                     h(.,.)

% the user can add to but should not delete from this list of variables

%-------------------------------------------------------------------------
%                          USER-SUPPLIED VARIABLES
%-------------------------------------------------------------------------

%  User-supplied entries:               Analog in Hansen, Singleton (1982)
%  ---------------------                ----------------------------------
%    1. xgmm:   nobs x k                  1. x:  T x k  = [x(1)',.., x(T)']
%    2. zgmm:   nobs x qgmm               2. z:  T x q  = [z(1)',.., z(T)']
%    3. theta0: lgmm x 1                  3. b0: l x 1
%    4. n:      integer, n>0              4. n:  integer, n>0
%                                       ----------------------------------
%                                       ----------------------------------
%    5. wgt      =  0                     W =  R(0)+sum_{j=1:n-1}(R(j)+R(j)')
%                =  1                       =  R(0)+sum_{j=1:n-1}(1-j/n)* 
%                                                                (R(j)+R(j)') 
%                =  2                       =  W described in Eichenbaum, 
%                                                et.al. (1986) 
%                                              (set nlag >=1)
%    6. restrict =  1                     R-statistic computed (0 otherwise)
%                                           (use GMMHC for moments with 
%                                            restrictions imposed)
%    7. induc: vector of indices          Set if restrict=1; gives indices
%       induc(i)<l, all i                   of theta vector that are not
%                                           constrained in computing R-stat.
%    8. parameters for optimization:
%       See UNCMIN
%
%    NOTE: xgmm and zgmm have same number of rows; thus for any row t
%          of zgmm is the instruments corresponding to the data in
%          xgmm(t,:) 
%

%-------------------------------------------------------------------------
%              Problem: HANSEN/SARGENT LQ economy
%-------------------------------------------------------------------------

% load hslqtest   ... which contains xgmm, Theta

load hslqtest
theta0   = theta0(1:5);
zgmm     = ones(length(xgmm),1);

[H,dH]=gmmh(theta0);
del =diag(max(abs(theta0)*1e-7,1e-8))
p=length(theta0);
for i=1:p;
  dh(:,i:p:p*p)  =   ..
       .5*(gmmh(theta0+del(:,i))-gmmh(theta0-del(:,i)))/del(i,i);
end;

save test2
