In panel data on Chinese establishments spanning the 2001 WTO accession, import competition is associated with increases in revenue productivity. We propose a model that interprets this (and additional evidence) as firms choosing to differentiate their products to escape import competition. In the model, the profit from endogenous differentiating is decreasing in trade costs and is an inverted U-shaped function of productivity. We estimate the model and study a counterfactual trade liberalization. In response to import competition, firms differentiate their products and increase their markups, thereby increasing revenue productivity as in the data. Since product differentiation is underprovided by the market, the endogenous differentiation increases welfare relative to a model without firms’ option to differentiate. So, the model rationalizes the positive relationship between import competition and revenue productivity in the data, and it puts forth a new source of gain from trade.