This paper analyzes endogenous fluctuations in total factor productivity (TFP) in a dynamic general equilibrium model with heterogeneous agents, and illustrates the interaction of credit market frictions, asset prices, the entry and exit of firms, and fluctuations in TFP in response to firm-level productivity and aggregate credit-market shocks. I also analyze the effect of bankruptcy and foreclosure laws on fluctuations in TFP through their effect on credit market frictions.