We report a detailed study of the electronic and structural properties of the 39K superconductor MgB 2 and of several related systems of the same family, namely Mg 0.5 Al 0.5 B 2 , BeB 2 , CaSi 2 and CaBeSi. Our calculations, which include zone-center phonon frequencies and transport properties, are performed within the local density approximation to the density functional theory, using the full-potential linearized augmented plane wave (FLAPW) and the norm-conserving pseudopotential methods. Our results indicate essentially three-dimensional properties for these compounds; however, strongly two-dimensional σ-bonding bands contribute significantly at the Fermi level.Similarities and differences between MgB 2 and BeB 2 (whose superconducting properties have not been yet investigated) are analyzed in detail. Our calculations for Mg 0.5 Al 0.5 B 2 show that metal substitution cannot be fully described in a rigid band model. CaSi 2 is studied as a function of pressure, and Be substitution in the Si planes leads to a stable compound similar in many aspects to diborides.