Dear Statalisters,

I just started using Stata. I would like to create a panel data for each patient and count number of different active medications in a given month. In my dataset, there are five columns:
patient_id, first_detected i.e. the first time (month-year) given patient started to take the given medication, last_detected i.e. the last time given patient started to take the given medication, category i.e. the category of the medication.
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(patient_id first_detected last_detected category)
1 648 701  665
1 658 661  721
1 658 662  850
1 658 666 1033
1 658 666 1761
1 658 666 2140
1 658 695  239
1 658 695  843
1 658 695  873
1 658 695 1037
1 658 695 1039
1 658 695 1507
1 658 695 2022
1 658 695 2828
1 658 695 2859
1 658 695 2892
1 658 701  533
1 659 701 2499
1 662 666 1105
1 666 695 1245
1 695 695 1040
1 695 695 1109
1 695 695 2478
1 695 695 2888
1 695 701 1862
2 622 637 1293
2 622 637 2892
2 622 643  171
2 622 662  850
2 622 662 1118
2 622 662 1396
2 622 662 2408
2 622 691 1331
2 622 695 2022
2 622 701 1716
2 622 701 2137
2 622 701 2139
2 622 701 2139
2 622 701  264
2 622 701 1308
2 622 701 2911
2 622 701    .
2 627 630 2067
2 627 637 2310
2 628 701    .
2 631 665 1827
2 632 637   70
2 634 701  570
2 636 639  851
2 636 642 2772
2 636 700  849
2 636 700  974
2 636 701    .
2 636 701    .
2 636 701    .
2 637 701    .
2 637 701  285
2 638 642  109
2 638 643  288
2 639 639    2
2 639 639 1918
2 640 701    .
2 641 687 1394
2 642 642 1526
2 642 642 2381
2 642 673 2300
2 694 694  568
2 694 694 1070
2 694 699 2047
2 694 701 2761
2 694 701 2761
2 694 701 2761
2 694 701 2761
2 694 701 2761
2 694 701 2761
2 694 701 2761
2 694 701 2761
2 694 701 2761
2 694 701 2761
2 694 701 2761
2 694 701 2761
2 694 701 2761
2 694 701 2761
2 694 701 2761
2 694 701 2761
2 694 701 2761
2 694 701 2761
2 694 701 2761
2 695 701 2761
2 695 701 2761
2 697 701 2761
3 648 701  665
3 695 695  239
3 695 695  841
3 695 695  843
3 695 695  858
3 695 695  863
3 695 695  869
3 695 695  873
3 695 695 1037
end
format %tm first_detected
format %tm last_detected
In a separate data file, I also have each patient’s blood values. In my analysis, I am interested in modelling doctors’ medication prescription behavior given previous and active medication use of patients and their blood values. How can I count the number of active medication that patients use and their previous medication usage?
My second and third questions are on modelling advice.
Do I need to use all the data available for each patient at the monthly level or I can simply use a single observation for each event? In the former case, there would be lot of zeros whereas in the latter case, DV would always be 1 and I will use the information available from the month before the adoption of new medication. Do I need to specify the patient_id when I stset the data? I would like to stratify by patient_id/
I also would like to model abonnement of drugs, do I need a separate regression for that or I can actually model both adoption and abonnement in a single regression, like using a competing event specification?
I purchased the Event History Analysis book by Paul Allison, although I think understood the concepts, I still would love to have some advice on the modelling decision.

Thanking you in advance.