help mata mz_trimrows()
-------------------------------------------------------------------------------

Title

mz_trimrows() -- Trims rows from the top and/or bottom of a matrix

Syntax

transmorphic matrix mz_trimrows(x, p, d)

where

x: transmorphic matrix from which rows are to be trimmed

p: real scalar containing the number of rows which must be removed from the top of matrix x

d: real scalar containing the number of rows which must be removed from the bottom of matrix x

Description

mz_trimrows() returns a matrix which is the matrix x with its top and/or bottom rows removed. If p = d = 0, then no rows will be removed from the matrix.

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_trimrows(x, 2, 3) 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 | +-----------------+

To remove only the first two rows of x, we set

: mz_trimrows(x, 2, 0) 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 | +-----------------+

To remove only the last three rows of x, we set

: mz_trimrows(x, 0, 3) 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 | +-----------------+

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_trimrows(A, 1, 2) 1 2 3 4 +-------------------------+ 1 | a21 a22 a23 a24 | 2 | a31 a32 a33 a34 | +-------------------------+

Conformability

mz_trimrows(x, p, d) x: n x c p: 1 x 1 d: 1 x 1 result: q x c, q <= n

Diagnostics

mz_trimrows() aborts with error if p or d is negative. Likewise if p or d is equal to the number of rows of x.

Source code

mz_trimrows.mata

Author

Diallo Ibrahima Amadou, zavren@gmail.com

Also see

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