We study the impact of time-varying macroeconomic conditions on optimal dynamic capital structure for a cross-section of firms. Our structural-equilibrium framework embeds a contingent-claim corporate financing model within a consumption-based asset-pricing model. We investigate the effect of macroeconomic conditions on asset valuation and optimal corporate policies, and of preferences on capital structure. While capital structure is pro-cyclical at dates when firms re-lever, it is counter-cyclical in aggregate dynamics, consistent with empirical evidence. We also find that financially constrained firms choose more pro-cyclical policies and that leverage accounts for most of the macroeconomic risk relevant for predicting defaults, but is a poor measure of how preferences impact capital structure.