function lr = lr(mdata,p,alpha);
%LRTest   tests the null hypothesis of p lags in a VAR versus the 
%         alternative of p+1.
%         lr = lr(mdata,p) takes the data in columns of mdata 
%         and the null value for p.

%         Ellen McGrattan, 9-14-04
%         Revised, ERM, 4-15-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);
[coef,se,resid] = autoreg(x(2:T,:),p);
Omega0          = resid'*resid/(T-p-1);
[coef,se,resid] = autoreg(x,p+1);
Omega1          = resid'*resid/(T-p-1);
k               = 1+n*(p+1);
lr              = (T-k)*(log(det(Omega0))-log(det(Omega1)));
