Open economy macroeconomics typically takes as exogenously given important aspects of the pattern of international trade. This paper shows how heterogeneity in trade costs and heterogeneity in productivities work together to jointly determine features of the pattern of international trade and the macroeconomic effects of productivity shocks. This is demonstrated in a general equilibrium macroeconomic model which allows the status of a good as traded or nontraded to be determined endogenously. The model includes two countries, each of which produces a distinct continuum of varieties through monopolistically competing firms. These goods are heterogeneous in terms of the technology in their respective production functions and the iceberg costs they incur in international trade; they also face fixed costs of exporting that are assumed constant across the varieties of each good. We posit convenient distributions for technology and for iceberg costs, which permit us to aggregate over the heterogeneous goods, and evaluate aggregate prices and quantities. Unlike open economy macro, trade theory has long studied the endogenous development of trade patterns. Traditionally, there has been an interest in trade theory in seeing how the goods along a continuum that are exported or imported are determined endogenously, with a range of goods possibly remaining untraded due to trade costs. This work typically ranks goods by their productivities, while assuming that the magnitude of trade costs is uniform across goods. Those goods with the greatest comparative advantage in one country or the other are traded, while those goods with small gains from trading relative to the uniform trade costs remain nontraded. However, since some goods are much more difficult to trade than others, the identity of a good as traded or nontraded is likely to be determined by heterogeneity in trade costs as well as by comparative advantage based on productivity. For example, the reason that many types of services are nontraded is not because countries are so similar in their productivities in these sectors; rather, they remain nontraded primarily because such services are particularly difficult to trade over long distances. Recent empirical work has emphasized that trade costs -- including tariff and nontariff barriers, shipping costs, and other associated costs of marketing and distribution -- vary greatly across classes of goods and play an important role in trade decisions. Other empirical work has also found support for the idea that some goods do switch over time between status as traded and nontraded. Our framework sheds light on the interaction between productivity and iceberg trade costs in determining which goods are traded. Because both affect the marginal costs of goods sold abroad, they enter the decision of whether to export in a parallel manner; hence it is the net effect of the two that determines the traded status of that good. A good that is especially costly to trade may be traded nonetheless, if the productivity of that good relative to other potentially tradable goods is sufficiently high to compensate for the extra trade cost. We show that a rise in heterogeneity in either dimension along the continuum of goods will tend to increase specialization in trade and raise the share of nontraded goods in an economy. This is because the marginal exporter compares his productivity net of transport costs to the average level of other exporters, as this determines the relative price and level of demand for his export in the foreign market. Consequently, a rise in heterogeneity of either productivity or transport costs will increase the average profitability of exporting relative to that of the marginal exporter, causing the marginal firm to exit the export market. Productivity and trade costs have different effects on relative prices, such as the real exchange rate, since technology heterogeneity generates heterogeneity in prices and hence production of goods sold at home, while transport cost heterogeneity only comes into play when goods are exported. Moreover, while productivity heterogeneity affects pricing in domestic and export markets equally under standard monopolistic-competition price setting, heterogeneous trade costs creates the cross-good variations in pricing to market and deviations from the law of one price that we observe in data. Our framework also has implications for the Balassa-Samuelson proposition that rich countries tend to have appreciated real exchange rates. First, we show that since the productivities of individual goods differ along a continuum, the distribution of technology improvements must be sufficiently biased toward goods with low trade costs for the real exchange rate to appreciate. Second, the magnitude of the Balassa-Samuelson effect depends upon the degree of heterogeneity in trade costs and the degree of the underlying distinction between traded and nontraded goods. Allowing the share of nontraded goods to rise endogenously in response to a biased productivity gain tends to double the size of the effect on the real exchange rate in simulations. Our analysis is related to several other recent papers in the literature. Obstfeld and Rogoff (NBER #7777, 2000) demonstrated that introducing trade costs into simple macro models can have dramatic implications for understanding a range of open economy issues. Bergin and Glick (NBER #9739, 2003) introduced heterogenous trade costs with a continuum of goods in a small-open macro model, but with output treated as an endowment, to analyze endogenous tradability, relative price variations, and current account imbalances. Ghironi and Melitz (2003) develop a macro model in which goods can switch between traded and nontraded; further their model allows for entry and exit from production, which our model does not permit. But their model allows heterogeneity only in the dimension of productivities, whereas our focus is on the role of heterogeneity in trade costs and how this interacts with productivity differences.