This paper studies the design of a pay-as-you-go social security system in an overlapping generations model where fertility is in part stochastic and in part determined through capital investment. If investments are publicly observable, pension benefits must be linked positively to the level of investment, and payroll taxes negatively to the number of children. The outcome is characterized by full insurance with all parents, regardless of their number of children, enjoying identical consumption levels. Without observability, benefits must increase, and payroll taxes decrease, with the number of children. The second-best level of investment, and the resulting average fertility rate, are less than their corresponding first-best levels.JEL classification: H55; J13.