Usually only male dogs do this and only if they are un-neutered or were neutered at an age where their hormones had already taken affect. It's so they can urinate on trees, buildings, whatever at a higher level. The higher the better because it means a taller animal. Also a dogs urine is like a text message to other dogs telling them about health, possibly food and other information. Sometimes you will see the alpha female lift her leg but it's never as high as a male and uncommon in any case.