Lisa
Lisa

Reputation: 141

Generating a variable which records the number of repetitions

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

Upvotes: 0

Views: 337

Answers (1)

TheIceBear
TheIceBear

Reputation: 3255

You can use: bysort ID : gen visit = _n

Upvotes: 3

Related Questions