Announcement

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

  • Origin and Destination Matrix

    Hi all, I'd appreciate your help.

    I need to build a matrix by origin and destination of migration flows within 22 States. This is a 22x22 matrix.

    I have the following variables:
    - Destination: 3000 observations with 22 possible States as destination
    - Origin: 3000 observations with 22 possible States as origin
    - Migration: 3000 observations with population equivalent for each observation

    This is:
    If I want to know the total migration flow I'd total migration. If I wat to know the total migration flow to state 1, I'd total migration by destination == state 1

    The following command would generate a non presentable table:
    table destination origin , statistic(total migration)

    However, I'd like to generate a matrix.

    Thanks in advance.

  • #2
    Hello,
    Were you able to figure this out? If you did, could you share the command you used?

    I am also trying to do something similar and I have no idea how to go about a matrix flow.

    I look forward to your response.

    Comment


    • #3
      Neither you nor the original poster gave a data example, advice prescribed in the StataList FAQ for new members, which is a likely cause of the relative lack of response. The answer to your question depends on the structure of your data set, and on what kind of matrix you want. Guessing on those two items, I'll offer the following illustration. If it isn't what you need, you can post back and explain is different about what you have and what you want.

      Code:
      // Example data
      clear
      input int (destination origin migration)
      1 1 8
      1 2 7
      1 3 3
      2 1 6
      2 2 4
      2 3 8
      3 1 6
      3 2 6
      3 3 1
      end
      //
      reshape wide migration, i(destination) j(origin)
      rename migration* migration_from*
      list
      // Do this if you actually want a Stata matrix.
      mkmat dest mig*, matrix(ToFrom)
      mat list ToFrom

      Comment

      Working...
      X