I believe good head retention is due to a number of factors, the main one being the viscous nature of dextrins which enclose the Co2 bubbles and therefore stop the foam from collapsing.
Most of the products that are formed to aid head retention are formed at the end of the mash, so short mash times and high PH can result in poor head retention. Using fresh High AA% hops can apparently help?
I've found that my beers gradually improve head retention over time as they mature (it's one indication I use to see if it's still "Green")
One other factor is poor rinsing of glasses leaving a residue of detergent, this will destroy the head on a beer in no time!
Other factors can be the amount of dissolved Co2, which can also change depending on the temp the beer is served at!