Results of ab initio calculations of crystal field parameters and the magnetocrystalline anisotropy energy (MAE) in RCo5 compounds, R2Fe17 and R2Fe17X3 (X = C,N) are discussed. For YCo5, calculated and experimental values for the MAE agree well. The relation between the MAE and the anisotropy of the orbital moments is discussed. Full potential band structure calculations have been used to study crystal field effects in GdCo5. A comparison is made with results from band structure calculations which employ the atomic-spheres approximation. The increase of the 4f MAE of 2-17 compounds due to C or N interstitials is shown to be related to the chemical nature of the interstitials.