help mata mz_decalen()
-------------------------------------------------------------------------------

Title

mz_decalen() -- Lags a matrix a specified number of times

Syntax

transmorphic matrix mz_decalen(x, n)

where

x: transmorphic matrix which is to be lagged

n: real scalar containing the number of lags

Description

mz_decalen() returns a new matrix which is the matrix x lagged n times. If n is positive, the matrix x is lagged back n times, then the first n observations of the new matrix are missing. If n is negative, the matrix x is lagged forward n times, then the last n observations of the new matrix are missing.

Remarks

Examples:

: x 1 2 3 4 +-----------------+ 1 | 1 3 5 6 | 2 | 4 3 2 1 | 3 | 7 5 3 2 | 4 | 8 9 0 1 | 5 | 4 6 8 9 | 6 | 3 2 6 7 | 7 | 1 4 5 7 | 8 | 7 2 4 6 | 9 | 1 4 0 3 | 10| 1 4 6 7 | +-----------------+

: mz_decalen(x, 2) 1 2 3 4 +-----------------+ 1 | . . . . | 2 | . . . . | 3 | 1 3 5 6 | 4 | 4 3 2 1 | 5 | 7 5 3 2 | 6 | 8 9 0 1 | 7 | 4 6 8 9 | 8 | 3 2 6 7 | 9 | 1 4 5 7 | 10| 7 2 4 6 | +-----------------+

: mz_decalen(x, -2) 1 2 3 4 +-----------------+ 1 | 7 5 3 2 | 2 | 8 9 0 1 | 3 | 4 6 8 9 | 4 | 3 2 6 7 | 5 | 1 4 5 7 | 6 | 7 2 4 6 | 7 | 1 4 0 3 | 8 | 1 4 6 7 | 9 | . . . . | 10| . . . . | +-----------------+

If we have a string matrix

: A 1 2 3 4 +-------------------------+ 1 | a11 a12 a13 a14 | 2 | a21 a22 a23 a24 | 3 | a31 a32 a33 a34 | 4 | a41 a42 a43 a44 | 5 | a51 a52 a53 a54 | +-------------------------+

we get

: mz_decalen(A, 2) 1 2 3 4 +-------------------------+ 1 | | 2 | | 3 | a11 a12 a13 a14 | 4 | a21 a22 a23 a24 | 5 | a31 a32 a33 a34 | +-------------------------+

Conformability

mz_decalen(x, n) x: r x c n: 1 x 1 result: r x c.

Diagnostics

mz_decalen() aborts with error if n is greater or equal to the number of rows of x.

Source code

mz_decalen.mata

Author

Diallo Ibrahima Amadou, zavren@gmail.com

Also see

Online: help for mz_trimrows(), [M-5] select(), ltimbimata