Multiple lags of time-series in one matrix

2017-06-09 14:16:41

Let's say I have some time-series z.

To get the first lag, I can do:

x1 = z(1:end-1);

y = z(2:end);

Then both x1 and y will have the same dimensions. How do I do this in a more general way to get also the lags of say 5 periods and 1 periods together in one matrix with same dimensions?

If I do

x1 = z(1:end-1);

x5 = z(1:end-5);

y = z(2:end);

then x1 will have a different length than x5.