More times than not, the chasing dog doesn't mean you any harm. It simply wishes to play with you. In essence, the dog thinks that you the cyclist is a form of playing fetch. Instead of being the stick, stop and pick one up. Toss it a few times and let the dog know you're friendly.
When you've had enough of the games and you're ready to go, throw the stick as far as you can, which should give you enough time to get away before the dog comes back with its retrieval.