'Generating all lags of a variable within panel dataset in STATA

I'm wondering if anyone can help me with the above. My dataset consists of match-level data for professional football (soccer), in which the managerial spell would be the ID and the game number within that spell would be the time variable. For example, PepGuardiolaManCity9 (ID) and game 53 of the spell (Time).

For each observation (match) > 1, I'd like to lag the result of the match, and another variable too (though if I can figure out how to do it for one variable it should then be straightforward to replicate). This obviously is relatively straightforward if you only wish to create 5 or 10 lags, but I require every lag, and this causes problems because of course, the length of each managerial spell will not be the same. Within my dataset spanning 20 years, Arsene Wenger has the longest managerial spell at 684 games.

Would the correct approach be to generate 683 lags (as new variables) and accept that for a lot of managerial spells there will be empty observations? I think I require the lags as individual variables as I'm planning on throwing everything into a lassologit at the end.

Apologies for the long post - I thought it would be better to be a thorough as possible. Many thanks in advance.

At this point I've not been able to find out how to approach this when working with panel data.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source