This paper makes two main contributions. First, we examine the long-run effect of foreign aid on domestic output for 59 developing countries using heterogeneous panel cointegration techniques to control for omitted variable and endogeneity bias and to detect possible cross-country differences in the output effect of aid. The main result is that aid has, on average, a negative long-run effect on output, but there are large differences across countries (in about a third of cases the effect is positive). Second, we use a general-to-specific variable selection approach to systematically search for country-specific factors explaining the cross-country differences in the estimated long-run effect of aid. In contrast to previous studies, we find that aid effectiveness does not depend primarily on factors such as the quality of economic policy, the share of a country's area that is in the tropics, the level of democracy or political stability. The results suggest that the cross-country heterogeneity in the output effect of aid can be explained mainly by cross-country differences in law and order, religious tensions and government size.