The rapid increase in house prices in the past few years, including during the COVID-19 pandemic, raises concerns about housing affordability. The price-to-income ratio is a widely-used indicator of affordability, but does not take into account important factors such as the cost of financing. The aim of this paper is to construct a measure of housing affordability that takes these factors into account for a large set of countries and long period of time. The resulting dataset covers an unbalanced panel of 40 countries over the period from 1970Q1 to 2021Q4. For each country, the index measures the extent to which a median-income household can qualify for a mortgage loan to purchase an average-priced home. To gauge the performance of the constructed indices, we compare them to other readily-available mesures of affordability and examine the evolution of the indices over time to understand the relevant drivers, including in a regression analysis to assess the extent to which government housing programs could contribute to improving affordability.