Generating a variable which records the number of repetitions

223 Views Asked by At

I have a longitudinal dataset in Stata in which IDs are repeated, I want to generate a new variable which repeats the number of IDs (like the column "visit" in the image). How can I write the code?

enter image description here

1

There are 1 best solutions below

0
On

You can use: bysort ID : gen visit = _n