Most agents stamp wherever they want.
Sometimes, in countries with exit stamps an officer will try to stamp the exit stamp next to the corresponding entrance stamp. However, that's just sometimes. Likewise, for travel requiring a visa, sometimes the officer will stamp next to that visa (or on top of it). But as others have said, they do what they want.