A common cause for head shaking is otitis externa, an inflammation of the external ear canal.
While ear mites, wax plugs, grass awns and other factors can cause the behavior, in most cases, there's an underlying allergy at work.
In addition to head shaking, dogs with otitis may have red and swollen ears.