convert data into a person-period format

Hello everyone,
I have got a dataset in the person (firm)- period format and the dataset has been sorted according to 'gvkey' in an ascending order and then 'fyear' in an ascending order. I am looking for commands so that I can insert a new variable 'id' (for firm-years with the same gvkey, the same id should be given) and another new variable 'period' (for firm year observations with the same 'id', the earlier firm year observation is 1, followed by 2, 3 etc). I have attached the dataset (in txt format) in which I have manually inserted the two new variables 'id' and 'period' for a few observations. Anyone who can help me with such SPSS commands that generate the two new variables automatically would be greatly appreciated. Thanks very much.
Best regards


It's been a while since you posted this, but I'm facing the same problem now, and I have no idea how to fix it. I've searched everywhere, nothing works.