function [beta,PROBLEM]=drawvarnewx(Y0,X0,sigmain,N,L,beta0,EX)
maxtrys=1000;
%conditional mean of the VAR coefficients
  mstar=vec(X0\Y0);  %ols on the appended data
  xx=X0'*X0;
  ixx=invpd(xx);  %inv(X0'X0) to be used later in the Gibbs sampling algorithm
  
%    vstar=kron(sigmain,ixx);
%    cvstar=chol(vstar);
%        chck=-1;                 %make sure VAR is stationary
% while chck<0
%        beta=mstar+(randn(1,N*(N*L+1))*(cvstar))';
% S=stabilityxxx(beta,N,L,1);
% if S==0
%     chck=10;
% end
% end

   [ beta,PROBLEM] = getcoefxx( mstar,sigmain,ixx,maxtrys,N,L,EX );
    if PROBLEM
        beta=beta0;
    end
       
   
 