Dear Nick and Surajit.
thank you both for your answers.
Nick, thank you very much for your in-depth answer ( very impressive, really !).
With the looping I intend to generate peer-group variables ( means) using a PISA-like dataset ( with info on same school (peers)) for each pupil separately, but the observation (pupil) itself left-out (dropped) since otherwise it would not be a peer-group. In case you are interesetd in helping / willing to help me to find a more efficient way to do that, pls tell me.
Yours sincerely,
Justina Fischer