This is a simple program which checks whether data are already sorted as wished. Only if not, Stata is asked to sort. Stata also makes such a check but it takes longer.
In Stata, simply run
cap ado uninstall sortcheck
net install sortcheck, from(https://github.com/felixholub/sortcheck/raw/master/src/)