Surprisingly, all of these calculations are built into the structural design and can be handled. All structures have a resonance, a 'rhythm' that once matched will create this effect. As part of structural design they will calculate the frequencies and tweak the structure around that to increase or decrease the frequency of the building. These are wrongly designed at times, and one of the most famous examples was the millenium bridge in London, which suffered due to the fact that its frequency matched nearly perfectly the rhythm of people walking. Once that little sway starts the public found themselves all matching each others strides as their bodies dealt with the movement, that exacerbated the effect.
Wind can also cause it, on bridges specifically, to quite horrifying outcomes.