So, I am following Abrigo Love (2015) and I want to write a Matlab code to produce the estimate of a panel VAR (I do know that there is a STATA code already done, but I am trying something different, so I need to create it from scratch). The main model is: $$ \Delta Y_{it} = \Delta \bar{ Y_{it}} A + \Delta e_{it} \\ \Delta Y_{it} = [\Delta y_{it}^1 ... \Delta y_{it}^k] \\ \Delta \bar{ Y_{it}} = [\Delta Y_{it-1} ... \Delta Y_{it-p}\Delta X_{it}] \\ \Delta e_{it} = [\Delta e_{it}^1,...,\Delta e_{it}^k] \\ A^T =[A_1^T, ... ,A_p^T, B^T] $$
and with $\Delta m_{it} $ either $ = m_{it} - m_{it-1} $ or $ = (m_{it} - \bar m_{it-1} ) \sqrt{( T_{it}/ T_{it} +1)}$. Notice the Vectors are row-vectors and not column-vectors (as some of us are used to).
Then Abrigo/Love say one should stack observations over panels and then over time (which is clear to me) and get the GMM estimator by (the usual GMM estimator) (:
$$ A = ( \Delta \bar Y^T Z \hat W Z^T \Delta \bar Y)^{-1} (\Delta \bar Y^T Z \hat W Z^T \Delta Y ) $$
Here is the question: how to write $\Delta Y$, $\Delta \bar Y$, and $ Z$ in Matlab? I know Z should be a bunch of instruments, but where do I get them and how should I stack it in this notation?
Furthermore, if I wanted Z (the instruments) either to include or to be lags of $\Delta Y$, how should I do it?
I need to know how to put it in Matlab, so some answer in matrix-vector notation would be very helpful.