  We present a population synthesis study of the observed properties of the
magnetars, which allows for X-ray selection effects, investigating the
hypothesis that they are drawn from a population of progenitors that are more
massive than those of the normal radio pulsars. We assume that the anomalous
X-ray emission is caused by the decay of a toroidal or tangled up field that
does not partake in the spin down of the star.
  We find that we can explain the observed properties, such as the period and
field distributions and the Period - Period derivative diagram, if we suitably
parametrise the time evolution of the anomalous X-ray luminosity as an
exponentially decaying function of time.
  The magnetic flux of the neutron stars is required to be a strong function of
the progenitor mass with the magnetars arising from the mass range 20-45 solar
masses.
  Unlike with the radio pulsars, the magnetars only weakly constrain the birth
spin period, due to their rapid spin-down. Our model predicts a birthrate of
about 0.15-0.3 per century.
