Hi,
I have a dataset that has 3 variables:
1) mrn :unique identifier
2) test_results: Results for a certain test
3) window_test: categorical variable for time windows in which test was conducted.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long mrn byte test_results float window_test
 2414225 3 2
 2414225 2 1
 3756996 3 1
 3756996 2 1
 4160321 1 2
 4160321 2 1
 4231270 3 2
 4231270 2 2
 4299731 2 1
 4299731 3 1
 4299731 . 1
 5157409 1 1
 5157409 1 1
 5157409 3 2
 6652598 2 2
 6652598 3 2
 8015810 . 2
 8015810 2 2
 8015810 3 2
 8845307 2 2
 8845307 3 2
 9342528 2 1
 9342528 3 2
 9342528 2 1
 9555525 1 1
 9555525 2 2
10239853 2 1
10239853 1 2
10356327 2 2
10356327 1 2
10356327 2 1
10403855 1 2
10403855 3 1
10545028 3 2
10545028 2 2
11274594 3 2
11274594 1 2
11274594 . 2
11571452 1 2
11571452 2 2
11571452 2 1
11636404 2 1
11636404 3 1
14359277 2 2
14359277 . 2
14359277 1 2
14721856 1 2
14721856 2 2
16395204 2 2
16395204 1 2
16776320 3 1
16776320 2 2
18848234 4 4
18848234 2 1
18848234 . 2
18848234 . 1
19353820 1 1
19353820 2 1
19773159 2 2
19773159 1 2
20320134 3 2
20320134 2 2
20394141 2 4
20394141 3 2
20401303 2 1
20401303 1 2
20555913 2 1
20555913 1 1
20622687 4 2
20622687 3 2
20654079 2 1
20654079 3 2
20706787 3 2
20706787 2 2
20746840 3 1
20746840 1 2
20752380 1 1
20752380 3 1
20752380 2 2
20786254 2 1
20786254 1 2
20802605 2 2
20802605 1 2
20826555 1 2
20826555 2 1
20826555 2 2
20834062 2 1
20834062 1 2
20834062 2 2
20856391 1 1
20856391 . 2
20856391 2 1
20882859 2 1
20882859 1 1
20902751 3 2
20902751 4 2
21178315 3 2
21178315 2 2
21214573 1 4
21214573 2 2
end
I want to generate a new variable that can count each occurrence of mrn. It should look like the following:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long mrn byte(her2_method_ihc window_test seq)
 2414225 3 2 1
 2414225 2 1 2
 3756996 3 1 1
 3756996 2 1 2
 4160321 1 2 1
 4160321 2 1 2
 4231270 3 2 1
 4231270 2 2 2
 4299731 2 1 1
 4299731 3 1 2
 4299731 . 1 3
 5157409 1 1 1
 5157409 1 1 2
 5157409 3 2 3
end
Any help would be great. Thanks!
Anindit Chhibber