Announcement

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

  • Not sorted error when trying to generate new lagged variables

    Hello,

    I am working on a project where I want to study how inheritances affect labour supply of recipients via a Diff-in-Diff approach.
    I have a panel structure (it is not 100% done yet, still some issues) so I ran the code

    Code:
    mi xtset id survey
    and then

    Code:
    gen E = 1 if l.expectation == 2 & gift_received == 2
    replace E=2 if l.expectation == 1 & gift_received == 2
    replace E=3 if l.expectation == 2 & gift_received == 1
    replace E=4 if l.expectation == 1 & gift_received == 1
    However, I always get the issue of "not sorted". So I try to use sort varlist and sort varlist, stable but still get the same issue.

    Here is an example of my data with some variables.
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte survey int id byte(implicate expectation gift_received) long gift1_value
    1 123 1 2 2     .
    1 123 0 2 2     .
    1 123 5 2 2     .
    1 123 4 2 2     .
    1 123 2 2 2     .
    1 123 3 2 2     .
    2 234 3 2 1  7500
    1 234 5 2 1 15000
    1 234 3 2 1 15000
    1 234 4 2 1 15000
    1 234 1 2 1 15000
    2 234 5 2 1  7500
    2 234 1 2 1  7500
    1 234 2 2 1 15000
    2 234 2 2 1  7500
    2 234 4 2 1  7500
    2 234 0 2 1  7500
    1 234 0 2 1 15000
    1 345 4 1 1 25000
    1 345 2 1 1 25000
    1 345 0 1 1 25000
    1 345 3 1 1 25000
    1 345 1 1 1 25000
    1 345 5 1 1 25000
    1 456 4 1 1 50000
    1 456 3 1 1 50000
    2 456 5 2 2     .
    2 456 2 2 2     .
    2 456 3 2 2     .
    2 456 1 2 2     .
    1 456 1 1 1 50000
    2 456 4 2 2     .
    1 456 0 1 1 50000
    1 456 2 1 1 50000
    1 456 5 1 1 50000
    2 456 0 2 2     .
    1 567 4 2 2     .
    1 567 3 2 2     .
    1 567 5 2 2     .
    1 567 1 2 2     .
    1 567 0 2 2     .
    1 567 2 2 2     .
    1 678 4 2 2     .
    1 678 2 1 2     .
    1 678 1 2 2     .
    1 678 0 . 2     .
    1 678 5 2 2     .
    1 678 3 2 2     .
    1 789 2 2 1 50000
    1 789 1 2 1 50000
    1 789 4 2 1 50000
    1 789 0 2 1 50000
    1 789 5 2 1 50000
    1 789 3 2 1 50000
    end
    What is my mistake?

  • #2
    Going out on a limb here, but don't you have multiple datasets when you use mi? If so, could it be that you need to sort them all, not just the one you have one? I've never worked with mi, so I could be wrong. Also what do you mean with sort varlist? sort id survey?

    Comment


    • #3
      You should xtset your data before using L.

      Comment


      • #4
        Originally posted by Oscar Weinzettl
        mi means multiple imputations. It is still one big data set that is in stata right now. I just fail to understand sort and the error calling my data unsorted. I have performed the sort command across all my variables (which is what I mean with sort varlist) and yet still the issue remains.
        You shouldn't sort across all your variables. You should sort along the xtset variables if you want to use the lag operator.

        Comment

        Working...
        X