We study a two-sector economy with investments in human and physical capital and imperfect labor markets. Human and physical capital are heterogeneous. Workers and firms endogenously select the sector they are active in, and choose the amount of their sector-specific investments in human and physical capital. To enter the high-skill sector, workers must pay a fixed cost that we interpret as direct cost of education. Given the distribution of the agents across sectors, at equilibrium, in each sector there is underinvestment in both human and physical capital, due to non-contractibility of investments. A second source of inefficiency is related to the self-selection of the agents into the two sectors. It typically induces too many workers to invest in education. Under suitable restrictions on the parameters, the joint effect of the two distortions is that equilibria are characterized by too many people investing too little effort in the high skill sector. We also analyze the welfare properties of equilibria and study the effects of several tax-subsidy policies on the total expected surplus.