Quick question that may be quite simple to answer but I am having trouble wrapping my head around it.
Below I have pasted some example data.
We have our participant ID and a variable called numberofsample.
Code:
clear input float(ID numberofsample) 1 1 2 1 3 3 3 3 3 3 4 3 4 3 4 3 5 1 6 3 6 3 6 3 7 2 7 2 8 3 8 3 8 3 9 3 9 3 9 3 end
Participant ID 3 was included in 3 samples so has 3 records. etc.
I was wondering if there was any script that could essentially create a new var (lets call it experiment), that would make the data look like this (below)?
Code:
clear input float(ID numberofsample experiment) 1 1 1 2 1 1 3 3 1 3 3 2 3 3 3 4 3 1 4 3 2 4 3 3 5 1 1 6 3 1 6 3 2 6 3 3 7 2 1 7 2 2 8 3 1 8 3 2 8 3 3 9 3 1 9 3 2 9 3 3 end
if numberofsample is 2, then the first record within the ID would have experiment = 1 and then the second record experiment = 2
if numberofsample is 3, then the first record within the ID would have experiment = 1 and then the second record experiment = 2 and the third record experiment = 3
Any help would be super appreciated!
Kind regards,
Ryan
0 Response to Counting up within ID
Post a Comment