Hello,
I am hoping for advice on obtaining count data from a dataset in which individual data is located in multiple rows.A complication is that two DiagnosisIDs may be made on the same date.
In the example below I want to (a) obtain a count of distinct DiagnosisIDs by StudyID and (b) identify by StudyID a count of instances when DiagnosisID has changed from the first DiagnosisID made .
A dummy data example is below. In this example StudyID 6283 has 1 distinct DiagnosisID value while StudyID 3757 has 5. 6283 demonstrated there was no change in DiagnosisID, whereas there was for 3757.
I will eventually look at changes within orders, but being about to obtain the count data would be a very useful step. List is helpful, however, I want to be able to merge the count data into another data file.
Any assistance is appreciated.
I am hoping for advice on obtaining count data from a dataset in which individual data is located in multiple rows.A complication is that two DiagnosisIDs may be made on the same date.
In the example below I want to (a) obtain a count of distinct DiagnosisIDs by StudyID and (b) identify by StudyID a count of instances when DiagnosisID has changed from the first DiagnosisID made .
A dummy data example is below. In this example StudyID 6283 has 1 distinct DiagnosisID value while StudyID 3757 has 5. 6283 demonstrated there was no change in DiagnosisID, whereas there was for 3757.
I will eventually look at changes within orders, but being about to obtain the count data would be a very useful step. List is helpful, however, I want to be able to merge the count data into another data file.
Any assistance is appreciated.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int StudyID str10 OrderMadeDate str9 OffenceDate str10 DiagnosisDate int DiagnosisID 6283 "5/26/2016" "4/17/2014" "9/23/2013" 1519 6283 "5/26/2016" "4/17/2014" "12/24/2013" 1519 6283 "5/26/2016" "4/17/2014" "11/10/2013" 1519 3757 "12/03/2016" "2/07/2016" "8/29/2013" 1527 3757 "12/03/2016" "2/07/2016" "7/17/2014" 1779 3757 "12/03/2016" "2/07/2016" "11/19/2015" 1779 3757 "12/03/2016" "2/07/2016" "11/26/2015" 1779 3757 "12/03/2016" "2/07/2016" "10/24/2015" 1780 3757 "12/03/2016" "2/07/2016" "8/29/2015" 1784 3757 "12/03/2016" "2/07/2016" "9/26/2015" 1784 3757 "12/03/2017" "2/07/2017" "10/08/2016" 1784 3757 "12/03/2016" "2/07/2016" "9/21/2015" 1800 end
Comment