
function [beta, btilde] = OPdrawbeta(z,x,invB0b0,Btilde)

% This function draws beta for the ordinal probit model
% Output
%--------------------------------------------------------------------------
% beta      : Gibbs draw of beta, a column vector
% btilde    : posterior mean
% Input
% z         : Gibbs draw of Latent response variable, a column vector
% x         : covariate matrix including a column of ones
% invB0b0   : inverse of prior covariance times prior mean 
% Btilde    : posterior covariance matrix
%--------------------------------------------------------------------------

k       = size(x,2);
btilde  = Btilde*(invB0b0 + x'*z);       % posterior mean
L       = chol(Btilde,'lower');
beta    = btilde + L*mvnrnd(zeros(k,1), eye(k))';

end