# Construct matrix of stacked variables in VAR regression

I am trying to NOT use packages for the estimation of models in order to have a deeper understanding of how things work. Currently, I am trying to estimate a VAR(1) (vector autoregression of first order) and my question is about how to construct the matrix of dependent and independent variables.

Theoretically, my model is:

$\binom{x_t}{y_t} = \binom{c_1}{c_2} + \begin{pmatrix} a_{11} & a_{12}\\ a_{21} & a_{22} \end{pmatrix}\binom{x_{t-1}}{x_{t-2}} + \binom{u_{1,t}}{u_{2,t}}$

As for the matrix of dependent variables, it should be easy enough. I just need to stack xt and zt. However, I don't know how to construct the matrix of independent variables. I read that VAR is very similar to SUR (Seemingly Unrelated Regressions) so I think that the matrix of independent variables should be a block diagonal matrix, but what should it look like? Especially if I want to add a constant and a time trend to the model?

Thank you.

If you have $n$ variables and $p$ lags, let $k\equiv np+1$ and define the $k\times1$ vector $$x_t\equiv[1,y_{t-1}^\top,y_{t-2}^\top,\ldots,y_{t-p}^\top ]^\top,$$ where $y_{t-j}=(y_{t-j,1},\ldots,y_{t-j,n})^\top$. The OLSE of a regression of $y_{it}$ on $x_t$ is $$\underset{(k\times 1)}{\hat{\phi}_{i,T}}=\left[\sum_{t}x_tx_t^\top\right]^{-1}\left[\sum_{t}x_ty_{it}\right]$$ Stack $$\underset{(nk\times 1)}{\hat{\phi}_{T}}\equiv\left( \begin{array}{c} \hat{\phi}_{1,T} \\ \hat{\phi}_{2,T} \\ \vdots \\ \hat{\phi}_{n,T} \\ \end{array} \right)$$