We study the division of labor within production systems and look for the optimal grouping of tasks into firms. Using a unique dataset on the global automobile industry, we present evidence consistent with the prediction that pairs of tasks requiring more frequent mutual adaptation are more likely to be performed by the same firm. By taking account of interdependencies between tasks, our econometric approach generalizes standard make-or-buy analysis and yields improvements in predictive accuracy.