Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Generate matrices that satisfy constraints on row and column sums

    I have what amounts to a programming challenge, as opposed to a data-analytical challenge, and I'm less adept with Mata. I have constraints that tell me the column sums and row sums of a matrix A and I need to find the combination of all A_ij values that are satisfy these constraints. Ideally, the values of the matrix would be integers but if using real numbers substantially eases the programming task, I can live with it. This topic is related to this thread and this thread but because I'm dealing with row and column constraints simultaneously, this is a substantially more complex problem.

    To give a simpler illustration than what I'm dealing with but gets at the challenge, assuming A is a 3x3 matrix and I have constraints:

    row sum of i_1-3 across j_1-3 is (1, 15, 8)
    and simultaneously, the columns must sum to

    col sum if j_1-3 over i_1-3 is (23, 12, 9).
    Or, to visualize the same thing is tabular format:
    1 2 3 rowsum
    1 A11 A12 A13 1
    2 A21 A22 A23 15
    3 A31 A32 A33 8
    colsum 23 12 9
    I need to find the unique combinations of A_ij that sum to the column and row constraints.

    My plan is to collect each unique value of A that satisfies the constraints and check it against an index. I will select the value of A that maximizes the index.

    To make this less abstract and to motivate the problem, you can think of the rows and columns as _something like_ my sampling frame. For administrative reasons outside my control, I need to select a certain number of cases within industries (columns) and occupations (rows) that add up to the row/col sums provided. I fully realize the resulting samples will not be random (in fact, cannot be fully random) but again that is a matter out of my control.

    Any ideas and help to get me started would be enormously appreciated!
Working...
X