Announcement

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

  • Sorting issue when sort is expanded by a variable

    Hello,

    I have an issue running the following command

    Code:
    sort id _mi_m survey expectation gift_received
    
    bys id _mi_m: gen treatment=0 if (expectation==2 & f.gift_received==2 & gift_total < 50000000) | (l.expectation==2 & gift_received==2 & gift_total < 50000000)
    If I do this, it tells me error (5) not sorted. I can and have run this code without any issue without the _mi_m variable. However, my data uses multiple imputations and if I don't sort those my results are not fully correct as far as I understand it. So I want to expand my sort list to include the imputation observation variable to make sure those are sorted too. Yet this gives me an error. What have I done wrong or what am I missing?

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int id byte(_mi_m survey expectation gift_received)
     27 0 2 1 2
     27 1 2 1 2
     27 2 2 1 2
     27 3 2 1 2
     27 4 2 1 2
     27 5 2 1 2
     36 0 1 2 1
     36 0 2 2 2
     36 1 1 2 1
     36 1 2 2 2
     36 2 1 2 1
     36 2 2 2 2
     36 3 1 2 1
     36 3 2 2 2
     36 4 1 2 1
     36 4 2 2 2
     36 5 1 2 1
     36 5 2 2 2
     67 0 1 2 1
     67 0 2 2 1
     67 1 1 2 1
     67 1 2 2 1
     67 2 1 2 1
     67 2 2 2 1
     67 3 1 2 1
     67 3 2 2 1
     67 4 1 2 1
     67 4 2 2 1
     67 5 1 2 1
     67 5 2 2 1
     86 0 1 2 1
     86 0 2 2 2
     86 1 1 2 1
     86 1 2 2 2
     86 2 1 2 1
     86 2 2 2 2
     86 3 1 2 1
     86 3 2 2 2
     86 4 1 2 1
     86 4 2 2 2
     86 5 1 2 1
     86 5 2 2 2
     92 0 1 2 2
     92 0 2 2 2
     92 1 1 2 2
     92 1 2 2 2
     92 2 1 2 2
     92 2 2 2 2
     92 3 1 2 2
     92 3 2 2 2
     92 4 1 2 2
     92 4 2 2 2
     92 5 1 2 2
     92 5 2 2 2
    128 0 1 2 2
    128 0 2 2 2
    128 1 1 2 2
    128 1 2 2 2
    128 2 1 2 2
    128 2 2 2 2
    128 3 1 2 2
    128 3 2 2 2
    128 4 1 2 2
    128 4 2 2 2
    128 5 1 2 2
    128 5 2 2 2
    130 0 1 1 1
    130 1 1 1 1
    130 2 1 1 1
    130 3 1 1 1
    130 4 1 1 1
    130 5 1 1 1
    178 0 1 2 1
    178 1 1 2 1
    178 2 1 2 1
    178 3 1 2 1
    178 4 1 2 1
    178 5 1 2 1
    303 0 1 1 2
    303 1 1 1 2
    303 2 1 1 2
    303 3 1 1 2
    303 4 1 1 2
    303 5 1 1 2
    484 0 1 2 1
    484 0 2 2 2
    484 1 1 2 1
    484 1 2 2 2
    484 2 1 2 1
    484 2 2 2 2
    484 3 1 2 1
    484 3 2 2 2
    484 4 1 2 1
    484 4 2 2 2
    484 5 1 2 1
    484 5 2 2 2
    594 0 1 1 1
    594 0 2 2 2
    594 1 1 1 1
    594 1 2 2 2
    end

  • #2
    The use of F. and L. operators presupposes a sort on whatever you told tsset or xtset are panel identifier and time variables. Your prior sort seems at odds with that.

    Comment


    • #3
      So basically I either use mi xtset, which I am using, or I use sort "_mi_m" but not both? Do I understand that correcty?

      Comment

      Working...
      X