%------------------------------------------------------------------------------
% Runmleq_ur   Compute MLE estimates for the model with random walk
%              technology using the sample period 1959:1--2003:4.
%              In this case, restrict the problem to have only 2 shocks.
%              The likelihood function is in file mleq_ur_2s.m
%
                                                                                
%              Ellen McGrattan, 2-16-02
%              Revised, ERM, 3-16-04
                                                                                
%------------------------------------------------------------------------------
%load uszvarq_ur.dat
global ZVAR
t    = uszvarq_ur(:,1);
ZVAR = uszvarq_ur(:,2:5);

[x1,f,g,code,status]   = uncmin(x0,'mleq_ur_2s',0);
[x1,f,g,code,status]   = uncmin(x1,'mleq_ur_2s',0);
[L,Sbar,P0,P,Q]        = mleq_ur_2s(x1);
ind   = [1,1,0,0, ...
         0,0,0,0, 0,1,0,0, 0,0,0,0, 0,0,0,0, ...
         1,0,0,0,   1,0,0,     0,0,       0]';
param = zeros(30,1);
param(find(ind)) = x1;

[L,Lt] = mleseq_ur(param,ind);

del = diag(max(abs(param)*1e-4,1e-8));
for i=1:length(param);
  if ind(i);
    [f1,f2] = mleseq_ur(param+del(:,i),ind);
    [m1,m2] = mleseq_ur(param-del(:,i),ind);
    dL(i,1)  = (f1-m1)/(2*del(i,i));
    dLt(i,:) = (f2-m2)'/(2*del(i,i));
  end;
end;
dLt =dLt(find(ind),:);
sum1=0;
[n,m]=size(dLt);
for t=1:m;
  sum1=sum1+dLt(:,t)*dLt(:,t)';
end;
se=diag(sqrt(inv(sum1)));

disp('Results from Maximum Likelihood Estimation')
disp('------------------------------------------')
disp(' ')
disp('   Parameters    Standard Errors (dL*dL'')')
disp('   ---------------------------------------')
disp(sprintf('   %9.3e         %9.3e  \n',[x1,se]'))
fprintf('   Log-Likelihood = %9.3f ',L)
disp(' ')
disp(' ')

                                                                                
