Which expression is valid? I am getting confused due to the notations in the textbook:
$e$ is $n$ by $1$ vector. $x$ is $n$ by $k$ vector. ($n$ observations, $k$ regressors).
(1) $var(\beta|X)$
$var(\beta|X)=E[(\beta-E(\beta|X)(\beta-E(\beta|X))'|X]$
$var(\beta|X)=E[(\beta-E(\beta|X)(\beta-E(\beta|X))']$
$var(\beta|X)=E[(\beta-E(\beta)(\beta-E(\beta))'|X]$
(2) $cov(\beta|X)$
$cov(\beta,e|X)=E[(\beta-E(\beta|X)(e-E(e|X))'|X]$
$cov(\beta,e|X)=E[(\beta-E(\beta|X)(e-E(e|X))']$
$cov(\beta,e|X)=E[(\beta-E(\beta)(e-E(e))'|X]$
It is the first option in both cases.
The conditional variance for a random vector $Y = (Y_1,\ldots, Y_n)'$ is defined as \begin{equation*} \operatorname{Var}(Y\mid X) = E\bigl[(Y-E[Y\mid X])(Y-E[Y\mid X])'\mid X \bigr]. \end{equation*} Here $Y$ is a column vector by standard notation, i.e. has dimension $n\times 1$ and $X$ is another random variable.
Compare to the one-dimensional variance that you are probably familiar with, \begin{equation*} \operatorname{Var}(Y\mid X) = E\bigl[ (Y-E[Y\mid X])^2\mid X\bigr] \end{equation*}
Heuristically, to go from the one-dimensional to the multidimensional, we "expand the parenthesis". That gives wrong dimensions for the multiplication, however. Now, which of the two should be transposed? I find it easy to remember dimensions by remembering that we say variance and covariance matrices. $YY'$ is a matrix and $Y'Y$ is a scalar.
For the covariance, \begin{equation*} \operatorname{Cov}(Y,Z\mid X) = E\bigl[(Y-E[Y\mid X])(Z-E[Z\mid X])'\mid X\bigr]. \end{equation*}