I have a longitudinal/long layout dataset in Stata in which RecordIDs are repeated/ I want to generate a new variable which shows the number of times each ID is repeated. How can I write the code?
I tried:
bysort RecordID : gen repeat_no = _n
but I'm getting the serial number of the times of repeats.
I want a variable to store the total number of times each ID is repeated (like shown in the image).enter image description here
bysort RecordID : gen repeat_NO = _N
For documentation of these basic constructs, see e.g.
help _variables