The quality of the foam in any given glass of beer is the result of many of factors: how the beer was brewed, the ingredients used, the level of carbonation, the serving glass, and even how the beer was poured. Foam dissipates quickly if there are any residual oils in the glass or even on your lips. Pouring the beer down the side of the glass rather than straight down the middle will also result in a less than perfect head.
The amount and quality of foam can also depend on the style of beer. Those hefeweizens traditionally sport some of the more impressive heads of foam. On the other hand, high-alcohol beers like barley wines and imperial stouts have much less since alcohol inhibits foam formation. The majority of ales and lagers fall somewhere in the middle of these two extremes.