Electronic and dynamical properties of MgB2 and related compounds