__Title__

**[R] mat_capp** -- Operators on matrices by names rather than positions

__Syntax__

**mat_capp** *mat1* **:** *mat2* *mat3* [**,** **miss(***#***)** **cons** **ts** ]

**mat_rapp** *mat1* **:** *mat2* *mat3* [**,** **miss(***#***)** **cons** **ts** ]

**mat_order** *mat1* **:** *mat2* *mat3*

__Description__

**mat_capp** creates matrix *mat1* by appending the columns of the matrices
*mat1* and *mat2* matched on the row-names of *mat2* and *mat3*. Thus the number
of columns of *mat1* equals the sum of the numbers of columns of *mat2* and
*mat3*.

If **miss** is not specified, the row names of *mat2* and of *mat3* should match
by equation and name, though they need not be in the same order.

**mat_rapp** performs a similar rowwise operation.

**mat_order** returns a matrix *mat1* that contains the values of *mat2* with
rows and columns ordered as in *mat3*. The row and column names of *mat2*
and *mat3* should match exactly.

In all cases, *mat1* may be the same matrix as *mat2* or *mat3*.

__Options__

**miss(***#***)** specifies that the rows of *mat2* and *mat3* are matched by equation
and name. Missing elements corresponding with unmatched combinations
of rows are set to *#*. Rows of *mat3* that match an equation, but not a
name, of *mat2* are inserted at the end of the equation in *mat1*. Rows
of *mat3* that do not match any equation are inserted at the end of
*mat1*.

**cons** specifies that rows corresponding with variable **_cons** should be
moved to the end of the equation.

**ts** specifies that rows with names with a time-series operator are
inserted at the end of the corresponding variable.

__Examples__

**Ex 1**

b1 b2 c1
a1 1 2 a3 13
z1 = a2 3 4 z2 = a1 11
a3 5 6 a2 12

**. mat_capp z12 : z1 z2**

b1 b2 c1
a1 1 2 11
z12 = a2 3 4 12
a3 5 6 13

**Ex 2**

z11 z12 z11 z13
A:a1 1 5 A:a1 11 12
z1 = A:a2 2 6 z2 = A:a3 21 22
B:b1 3 7 B:b1 31 32
e1 4 8 C:c1 41 42

**. mat_capp z12 : z1 z2, miss(.)**

z11 z12 z11 z13
A:a1 1 5 11 12
A:a2 2 6 . .
z12 = A:a3 . . 21 22
B:b1 3 7 31 32
e1 4 8 . .
C:c1 . . 41 42

**Ex 3**

b1 b2 b3 b1 b3 b2
a1 1 5 9 a1 11 13 12
z1 = a2 2 6 10 z2 = a4 21 23 22
a3 3 7 11 a3 31 33 32
a4 4 8 12 a2 41 43 42

**. mat_order z12 : z1 z2**

b1 b3 b2
a1 1 9 5
z12 = a4 4 12 8
a3 3 11 7
a2 2 10 6

__Acknowledgment__

These commands were written by Jeroen Weesie, Department of Sociology,
Utrecht University, The Netherlands.