function sic = sic(mdata,pmax,alpha);
%SIC      computes the Schwarz information criterion for a VAR
%         with at most pmax lags.
%         sic = sic(mdata,pmax,alpha) uses data in mdata, a 
%         maximum lag pmax and a differencing parameter alpha
%         and returns the criterion (to be minimized).
%
                                                                                
%         Ellen McGrattan, 9-14-04

prd      = mdata(:,1);
hpc      = mdata(:,2);
nobs     = length(hpc);
x        = log(prd);
n        = log(hpc);
x        = x-x(1);
n        = n-n(1);
dx       = x(2:nobs)-x(1:nobs-1);
dn       = n(2:nobs)-alpha*n(1:nobs-1);
x        = [dx,dn];
[T,n]    = size(x);

for p=1:pmax;
  [coef,se,resid] = autoreg(x(pmax-p+1:T,:),p);
  Omega           = resid'*resid/(T-pmax);
  sic(p)          = log(det(Omega))+n*(n*p+1)*log(T-pmax)/(T-pmax);
end;

