Beckham Law self-employed permanent establishment in Spain

Beckham Law self-employed permanent establishment: when can you keep the impatriate regime (and when do you lose it)?