help mata mz_pancolshape()
-------------------------------------------------------------------------------

Title

mz_pancolshape() -- Reorganizes, in columns, a panel data matrix for which the panels are presented by lines

Syntax

transmorphic matrix mz_pancolshape(W, c, f )

where

W: transmorphic matrix containing panel data

c: real scalar indicating the number of columns for the new panel data matrix

f: string scalar indicating how the user wants the panels to be presented

Description

mz_pancolshape() reshapes a t x (c * K) panel data set matrix W, to a (K * t) x c panel data matrix if the argument f takes the value "CK". K is the number of panels, t the number of observations in panels and c the number of columns of the new matrix. The "CK" is specified to reshape a panel data matrix that was remodeled by the mz_panrowshape() function in which the f argument took the value "CK". See mz_panrowshape() for more details on the "CK" and (c * K) specifications.

mz_panrowshape() reshapes a t x (K * c) panel data set matrix W, to a (K * t) x c panel data matrix if the argument f takes the value "KC". The "KC" is specified to reshape a panel data matrix that was remodeled by the mz_panrowshape() function in which the f argument took the value "KC". See mz_panrowshape() for more details on the "KC" and (K * c) specifications.

Remarks

Remarks are presented under the following headings:

Case where f takes the value "CK" Case where f takes the value "KC"

Case where f takes the value "CK"

Suppose we have a matrix V

: V 1 2 3 4 +---------------------+ 1 | 1 1 3.1 3.7 | 2 | 1 2 9.2 4.2 | 3 | 1 3 2.5 6.5 | 4 | 1 4 8.4 7 | 5 | 1 5 4.6 3.9 | 6 | 2 1 6.2 1.5 | 7 | 2 2 5 3.2 | 8 | 2 3 7.8 9.6 | 9 | 2 4 5.4 7.7 | 10 | 2 5 3.4 9.2 | 11 | 3 1 2.1 2.3 | 12 | 3 2 9 1.5 | 13 | 3 3 1.4 6.7 | 14 | 3 4 4.8 3.3 | 15 | 3 5 9.5 9.7 | +---------------------+ We reshape it using the mz_panrowshape() function in which the argument f takes the value "CK"

: matA = mz_panrowshape(V, 1, "CK") : matA 1 2 3 4 5 6 7 8 9 10 11 12 +-------------------------------------------------------------+ 1 | 1 1 3.1 3.7 2 1 6.2 1.5 3 1 2.1 2.3 | 2 | 1 2 9.2 4.2 2 2 5 3.2 3 2 9 1.5 | 3 | 1 3 2.5 6.5 2 3 7.8 9.6 3 3 1.4 6.7 | 4 | 1 4 8.4 7 2 4 5.4 7.7 3 4 4.8 3.3 | 5 | 1 5 4.6 3.9 2 5 3.4 9.2 3 5 9.5 9.7 | +-------------------------------------------------------------+

To reshape the matrix matA to the original matrix V, we use the mz_pancolshape() function in which the f argument takes the value "CK"

: matB = mz_pancolshape(matA, 4, "CK") : matB 1 2 3 4 +---------------------+ 1 | 1 1 3.1 3.7 | 2 | 1 2 9.2 4.2 | 3 | 1 3 2.5 6.5 | 4 | 1 4 8.4 7 | 5 | 1 5 4.6 3.9 | 6 | 2 1 6.2 1.5 | 7 | 2 2 5 3.2 | 8 | 2 3 7.8 9.6 | 9 | 2 4 5.4 7.7 | 10 | 2 5 3.4 9.2 | 11 | 3 1 2.1 2.3 | 12 | 3 2 9 1.5 | 13 | 3 3 1.4 6.7 | 14 | 3 4 4.8 3.3 | 15 | 3 5 9.5 9.7 | +---------------------+

Which is the same matrix as V. To be sure we use the asserteq() function

: asserteq(matB, V)

Nothing is returned, then the two matices are the same Case where f takes the value "KC"

We reshape the V matrix using the mz_panrowshape() function but the argument f takes the value "KC" : matC = mz_panrowshape(V, 1, "KC") : matC 1 2 3 4 5 6 7 8 9 10 11 12 +-------------------------------------------------------------+ 1 | 1 2 3 1 1 1 3.1 6.2 2.1 3.7 1.5 2.3 | 2 | 1 2 3 2 2 2 9.2 5 9 4.2 3.2 1.5 | 3 | 1 2 3 3 3 3 2.5 7.8 1.4 6.5 9.6 6.7 | 4 | 1 2 3 4 4 4 8.4 5.4 4.8 7 7.7 3.3 | 5 | 1 2 3 5 5 5 4.6 3.4 9.5 3.9 9.2 9.7 | +-------------------------------------------------------------+

To reshape the matrix matC to the original matrix V, we use the mz_pancolshape() function in which the f argument takes the value "KC"

: matD = mz_pancolshape(matC, 4, "KC") : matD 1 2 3 4 +---------------------+ 1 | 1 1 3.1 3.7 | 2 | 1 2 9.2 4.2 | 3 | 1 3 2.5 6.5 | 4 | 1 4 8.4 7 | 5 | 1 5 4.6 3.9 | 6 | 2 1 6.2 1.5 | 7 | 2 2 5 3.2 | 8 | 2 3 7.8 9.6 | 9 | 2 4 5.4 7.7 | 10 | 2 5 3.4 9.2 | 11 | 3 1 2.1 2.3 | 12 | 3 2 9 1.5 | 13 | 3 3 1.4 6.7 | 14 | 3 4 4.8 3.3 | 15 | 3 5 9.5 9.7 | +---------------------+

Which is the same matrix as V. To be sure we use the asserteq() function

: asserteq(matD, V)

Nothing is returned, then the two matrices are identical

Conformability

mz_pancolshape(W, c, f) W: t x (c * K) or t x (K * c) c: 1 x 1 f: 1 x 1 result: (K * t) x c, t = number of obs. in panel, K = number of panels

Diagnostics

mz_pancolshape() aborts with error if cols(W) is not divisible by c.

Source code

mz_pancolshape.mata

Author

Diallo Ibrahima Amadou, zavren@gmail.com

Also see

Online: help for mz_panrowshape(), ltimbimata