S.
My daughter did the same thing at age 3. Just give it time and remind her each time that she goes in her underwear that she is suppose to go on the potty. It took my daughter about six months to get it all right.
Do not stop her once she starts, constipation is much worse.
Good Luck!!!