Given the following variables (id
and partner
) in Stata, I would like to create a new variable (pid
) that is simply the consecutive partner counter within id
(as you can see, partner
is not consecutive). Here is a MWE:
clear
input id partner pid
1 1 1
1 1 1
1 3 2
1 3 2
2 2 1
2 3 2
2 3 2
2 3 2
2 5 3
2 5 3
end