Announcement

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

  • How to create a matrix from stata data in mata, using groups of observations as rows?

    Hey!

    I am currently trying to generate a matrix from stata data in mata, using groups of observations as rows. Normally I would collapse the data to the desired level of observations. I however do not want to ruin the dataset since this would not enable me to run regressions on the original level of observations anymore.

    The dataset looks something like an extended version of this: (each observation contains information about a route and airline, where route_airline and route are id (numeric) variables at different levels of observation)
    route_airline route airline1 airline2 airline3 airline4
    30011 3001 1 0 0 0
    30013 3001 0 0 1 0
    30014 3001 0 0 0 1
    30021 3002 1 0 0 0
    30022 3002 0 1 0 0
    30031 3003 1 0 0 0
    30032 3003 0 1 0 0
    30033 3003 0 0 1 0
    The desired matrix should be with a "collapsed" version of routes as rows and all airline.i as dummy variables as columns.

    Thanks a lot for your help!

    Frank

  • #2
    I do not understand your fear about "ruining" the data by collapsing it. As long as you use save to store a copy of your uncollapsed data before the collapse, and do not use save with the collapsed data and the same filename, your uncollapsed data remains available to you to recover with the use command. Perhaps what your are trying is more complicated, and if so, with more detail about your eventual objective, a better answer might be found.

    Comment


    • #3
      I see what you mean. I could of course save it, collapse it afterwards and then later on merge the two datasets again. (Since the newly generated matrix is needed in a regression with previous level of observation) This however seems like a somewhat provisional approach. If there is no other way, I could try that.

      Comment

      Working...
      X