ANSWER: To consider the age and knowing when the bad behavior warrants discipline with a spanking, turn to the Old Testament book of Proverbs where wise King Solomon gives us principles to follow in our everyday life.
A refusal to correct is a refusal to love; love your children by disciplining them. (Proverbs 13:24)
This definitely puts the responsibility on you as the parent. As someone who loves their child, you probably know their attitude more than a stranger. Allowing the child to have the control with their bad behavior is not showing them love.
Be sure to convey that you love them before the spanking so they will know you are not spanking in anger but in love. This may take a little practice. Don't get discouraged. You may have to count to 10 before actually spanking on your part of the session, so it won't be in anger. Then again, if it is done promptly, as is mentioned in this scripture, you may not need to do the counting. It is very important that it is done promptly, as a young child has a very short memory. Also, you may want to say a short prayer to ask God for the wisdom and self-control to discipline your child in love.
In regard to your question concerning at what age spanking is appropriate, Proverbs 19 says we are to disciple our children when they are at the age young enough to learn (verse 18).
No actual age is mentioned, leaving that up to the parent's discretion. However, it is VITAL that you instill attitudes of respect into your child before they reach school age for those who will be in authority over them, such as their parents, teachers, policemen, etc. That way, they will already have that attitude as they grow up and come into contact with other adults (Proverbs 29:17).
This would also include a principle of when a child accepts the parents guidance, they will not run wild. When they obey they will be happy.
The most important thing for a child to learn when he or she is very young is that they are loved. The second most important principle for a child to learn is that they need to obey their parents. Consider the admonition to adults in the New Testament book of Hebrews which states that God treats us just like his children (Hebrews 12:5). God corrects us because, like a good parent, he loves us (Hebrews 12:6). As the child grows into an adult they will always need to answer to someone, so it would be good to learn this important principle early on.
In regard to our (or any) society that considers spanking (disciplining) a form of child abuse, we must be discrete when spanking in public. Our nation has gone so far away from God and His laws that they think ANY kind of correction is abuse. Both leaders and citizens alike have listened to the erroneous teachings of Benjamin Spock, MD (1903-1998) who advocated very little physical discipline and was branded as the "father of permissiveness." It would be better not to spank in public but to wait until you get home or to a private place. One thing you could do would be to give the child something to work for. For instance, offer a reward to be given when you return home for good behavior while you are out. If there is an infraction then no reward is given.
Whatever you do, NEVER allow the child to go on being continually disrespectful and having the control in all situations. Take your child-rearing concerns in prayer to God the Father, our perfect parent. Then be patient and do the best you can, always seeking God's advice and the guidance he offers in the Bible.