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?