Stopping yourself from comparign yourself to others is something that happens once you stop caring so much about what other people are doing, focusing on what you want and whats best for you, and improving your self confidence.
Easier said than done... but I think the fact that you compare yourself to others is really the secondary issue caused by a self esteem problem, and there's no single way to deal with that. A lot of that will come with age and maturity. But if you're finding it to be a big problem, perhaps you should consider speaking to a counsellor about things.