Dear Statalists,
I want to count total number of patients at a hospital while a patient is waiting for treatment, after Evaluation, for each patient/observation.
The date variables are Start, Evaluation, and Treatment. I want to generate a variable that counts how many patients have a daterange from Start to Treatment that includes the current patient's Evaluation to End interval.
ie.
I have tried rangestat from SSC but it doesn't check a range. It counts number of observations with e.g. Start within the current observation's Evaluation to End range.
Thank you for your help!
Here's the dataex:
I want to count total number of patients at a hospital while a patient is waiting for treatment, after Evaluation, for each patient/observation.
The date variables are Start, Evaluation, and Treatment. I want to generate a variable that counts how many patients have a daterange from Start to Treatment that includes the current patient's Evaluation to End interval.
ie.
| ID | Start | Evaluation | End | Count |
| 1 | 1 Jan | 5 Jan | 7 Jan | 2 |
| 2 | 4 Jan | 8 Jan | 20 Jan | 3 |
| 3 | 13 Jan | 15 Jan | 18 Jan | 2 |
| 4 | 19 Jan | 20 Jan | 30Jan | 0 |
I have tried rangestat from SSC but it doesn't check a range. It counts number of observations with e.g. Start within the current observation's Evaluation to End range.
Thank you for your help!
Here's the dataex:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float ID int(Start Evaluation Treatment) 1 23644 23676 23694 2 23533 23562 23578 3 23407 23423 23442 4 23800 23821 23829 5 23875 23889 . 6 23887 . . 7 23611 23648 23649 8 23670 23696 . 9 23695 23765 23767 10 23709 23751 23765 11 23954 . . 12 23695 23759 23801 13 23538 23547 . 14 23643 23654 . 15 23778 23784 23796 16 23686 23715 23732 17 23918 23927 23935 18 23507 23519 . 19 23603 23637 . 20 23815 23865 23898 21 23428 23456 23478 22 23952 23962 23975 23 23505 23710 . 24 23757 23767 . 25 23757 23780 23794 26 23440 23458 . 27 23692 . . 28 23763 23780 23788 29 23412 23442 23445 30 23842 23875 23891 31 23944 23946 . 32 23862 23914 23927 33 23482 23487 . 34 23555 23575 23599 35 23569 23584 23612 36 23429 23464 23478 37 23786 23802 23815 38 23685 23725 23759 39 23792 23802 . 40 23625 23655 23656 41 23607 23619 . 42 23462 23486 . 43 23497 23519 . 44 23645 23651 . 45 23645 23658 23722 46 23650 23659 . 47 23469 23484 . 48 23582 23654 23660 49 23867 23882 23894 50 23931 23966 23974 51 23568 23577 23582 52 23602 23612 . 53 23388 23422 23423 54 23629 23633 . 55 23905 23918 23928 56 23864 23900 23914 57 23482 23511 23520 58 23798 23816 23838 59 23526 23528 23547 60 23651 23857 23913 61 23602 23645 23660 62 23533 23618 23612 63 23834 23858 . 64 23472 23483 . 65 23548 23574 23619 66 23883 23919 . 67 23668 23725 23779 68 23877 23891 23947 69 23597 23646 . 70 23660 23683 . 71 23659 23672 23696 72 23955 23967 . 73 23856 23871 . 74 23734 23749 . 75 23854 23862 . 76 23561 23574 23597 77 23820 23913 23935 78 23491 . . 79 23799 23800 23816 80 23661 23669 23674 81 23580 23591 23617 82 23637 23674 23694 83 23695 23696 23722 84 23752 23876 . 85 23749 23757 . 86 23899 23910 23928 87 23512 23534 . 88 23422 23442 23458 89 23877 23896 . 90 23720 23780 23806 91 23751 23764 23771 92 23603 23623 . 93 23680 23716 23731 94 23750 23779 23800 95 23756 23815 23816 96 23387 23396 23403 97 23573 23602 23614 98 23752 23808 23809 99 23807 23820 23837 100 23829 23861 23891 end format %td Start format %td Evaluation format %td Treatment rangestat (count) currently_in_treatment = ID if !missing(Start, Evaluation, Treatment), interval(Start Evaluation Treatment) *

Comment