Technical progress in originating and pricing mortgages has enabled a trend since 1979 toward relaxed credit standards for lending, reflected in rising foreclosure rates. We develop a methodology for decomposing the trend in mortgage performance into a part due to economic conditions and a part due to underwriting changes, and provide natural metrics or indices of underwriting quality and economic conditions. The recent mortgage debacle can be attributed about equally to each factor. Important underwriting characteristics were eased in the 1990s, but the negative effects of lower standards were masked by strong local and national economic conditions. After 2002, there was little change in observable loan characteristics, but loan performance still eroded, even after controlling for the economic environment. Our evidence suggests that erosion after 2002 must have arisen from underwriting covariates that are unobservable to investors, consistent with the hypothesis that moral hazard in “nonagency” securitizations caused underwriting risks to be mispriced.