r</span>
<span class="keyword">end</span>

Y = Y(lag+1:end,:); <span class="comment">%matrix of combined time series (first p terms removed, with constant vector)</span>
Y_= Y-LTM(ones(N-lag,1),:); <span class="comment">%matrix in terms of difference from long-term mean, no constant vector</span>

s.B_=inv(X_'*X_)*X_'*Y_;    <span class="comment">%compute VAR coefficients</span>
</pre><h2>3. Adjust VAR(p) coefficients for exogenous variables, if applicable<a name="5"></a></h2><pre class="codeinput"><span cl