Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to conduct a pre/post analysis using dates

    Hi everyone,


    I am relatively new to Stata and could use some assistance with conducting a pre/post analysis using dates. I have the client ID, client's enrollment status (i.e., when the client was open to receiving services), the service date (i.e., when the client received services), discharged date (i.e., when the client was discharged from the program), and service category (i.e., whether the services received were inpatient or outpatient services). I would like to determine:
    • The number/percentage of clients who engaged in services 3 months after they were discharged from the program
    • The number/percentage of clients who engaged in outpatient services 3 months prior to their enrollment in the program and 3 months after they were discharged
    • The number/percentage of clients who engaged in inpatient services since 2018 and 3 months prior to their enrollment in the program and 3 months after they were discharged
    • The percentage of consumers who decreased their engagement in inpatient services, had no change in inpatient service engagement, and increased inpatient service engagement
    This is the code I've used so far to determine clients who engaged in services 3 months prior to their enrollment in the program and 3 months after they were discharged from the program.

    /*IDENTIFY SERVICES THAT DISCHARGED/CLOSED CONSUMERS ENGAGED IN WITHIN 3 MONTHS PRIOR TO THEIR ENROLLMENT IN THE ISN PROGRAM (AKA PRIOR)*/
    gen cohort3=servicedate-enrollmentdate if enrollmentstatus=="Closed", after(servicedate)
    gen cohort_status="PRIOR" if cohort3<0&cohort3>=-90, after (cohort3)//3 months prior to their enrollment


    /*IDENTIFY SERVICES THAT DISCHARGED/CLOSED CONSUMERS ENGAGED IN WITHIN 3 MONTHS AFTER THEY DISCHARGED FROM THE ISN PRORGAM (AKA AFTER)*/
    gen cohortdc=servicedate-dischargeddate if enrollmentstatus=="Closed", after(cohort_status)
    gen dccohort_status="AFTER" if cohortdc>0&cohortdc<=90//3 months after discharge


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte clientid str6 enrollmentstatus int(enrollmentdate servicedate dischargeddate) str10 servicecategory
    4 "Closed" 21763 21459 21822 "Outpatient"
    4 "Closed" 21763 21459 21822 "Outpatient"
    4 "Closed" 21763 21482 21822 "Outpatient"
    4 "Closed" 21763 21486 21822 "Outpatient"
    4 "Closed" 21763 21486 21822 "Outpatient"
    4 "Closed" 21763 21536 21822 "Outpatient"
    4 "Closed" 21763 21536 21822 "Outpatient"
    4 "Closed" 21763 21536 21822 "Outpatient"
    4 "Closed" 21763 21553 21822 "Outpatient"
    4 "Closed" 21763 21558 21822 "Outpatient"
    4 "Closed" 21763 21559 21822 "Outpatient"
    4 "Closed" 21763 21595 21822 "Outpatient"
    4 "Closed" 21763 21602 21822 "Outpatient"
    4 "Closed" 21763 21602 21822 "Outpatient"
    4 "Closed" 21763 21628 21822 "Outpatient"
    4 "Closed" 21763 21628 21822 "Outpatient"
    4 "Closed" 21763 21628 21822 "Outpatient"
    4 "Closed" 21763 21629 21822 "Outpatient"
    4 "Closed" 21763 21629 21822 "Outpatient"
    4 "Closed" 21763 21634 21822 "Outpatient"
    4 "Closed" 21763 21656 21822 "Outpatient"
    4 "Closed" 21763 21658 21822 "Outpatient"
    4 "Closed" 21763 21658 21822 "Outpatient"
    4 "Closed" 21763 21658 21822 "Outpatient"
    4 "Closed" 21763 21671 21822 "Outpatient"
    4 "Closed" 21763 21672 21822 "Outpatient"
    4 "Closed" 21763 21677 21822 "Outpatient"
    4 "Closed" 21763 21689 21822 "Outpatient"
    4 "Closed" 21763 21692 21822 "Outpatient"
    4 "Closed" 21763 21704 21822 "Outpatient"
    4 "Closed" 21763 21726 21822 "Outpatient"
    4 "Closed" 21763 21760 21822 "Outpatient"
    4 "Closed" 21763 21832 21822 "Outpatient"
    4 "Closed" 21763 21833 21822 "Outpatient"
    4 "Closed" 21763 21837 21822 "Outpatient"
    4 "Closed" 21763 21844 21822 "Outpatient"
    4 "Closed" 21763 21844 21822 "Outpatient"
    4 "Closed" 21763 21852 21822 "Outpatient"
    4 "Closed" 21763 21873 21822 "Outpatient"
    4 "Closed" 21763 21889 21822 "Outpatient"
    4 "Closed" 21763 21895 21822 "Outpatient"
    4 "Closed" 21763 21895 21822 "Outpatient"
    4 "Closed" 21763 21923 21822 "Outpatient"
    4 "Closed" 21763 21923 21822 "Outpatient"
    4 "Closed" 21763 21936 21822 "Outpatient"
    4 "Closed" 21763 21937 21822 "Outpatient"
    4 "Closed" 21763 21944 21822 "Outpatient"
    4 "Closed" 21763 21951 21822 "Outpatient"
    4 "Closed" 21763 21952 21822 "Outpatient"
    4 "Closed" 21763 21965 21822 "Outpatient"
    4 "Closed" 21763 21970 21822 "Outpatient"
    4 "Closed" 21763 21976 21822 "Outpatient"
    4 "Closed" 21763 21987 21822 "Outpatient"
    4 "Closed" 21763 21994 21822 "Outpatient"
    4 "Closed" 21763 22008 21822 "Outpatient"
    4 "Closed" 21763 22013 21822 "Outpatient"
    4 "Closed" 21763 22032 21822 "Outpatient"
    4 "Closed" 21763 22032 21822 "Outpatient"
    4 "Closed" 21763 22041 21822 "Outpatient"
    4 "Closed" 21763 22046 21822 "Outpatient"
    4 "Closed" 21763 22053 21822 "Outpatient"
    4 "Closed" 21763 22054 21822 "Outpatient"
    4 "Closed" 21763 22057 21822 "Outpatient"
    4 "Closed" 21763 22061 21822 "Outpatient"
    4 "Closed" 21763 22064 21822 "Outpatient"
    4 "Closed" 21763 22067 21822 "Outpatient"
    4 "Closed" 21763 22068 21822 "Outpatient"
    4 "Closed" 21763 22068 21822 "Outpatient"
    4 "Closed" 21763 22074 21822 "Outpatient"
    4 "Closed" 21763 22075 21822 "Outpatient"
    4 "Closed" 21763 22075 21822 "Outpatient"
    4 "Closed" 21763 22075 21822 "Outpatient"
    4 "Closed" 21763 22076 21822 "Outpatient"
    4 "Closed" 21763 22082 21822 "Outpatient"
    4 "Closed" 21763 22085 21822 "Outpatient"
    4 "Closed" 21763 22090 21822 "Outpatient"
    4 "Closed" 21763 22090 21822 "Outpatient"
    4 "Closed" 21763 22091 21822 "Outpatient"
    4 "Closed" 21763 22092 21822 "Outpatient"
    4 "Closed" 21763 22103 21822 "Outpatient"
    4 "Closed" 21763 22109 21822 "Outpatient"
    4 "Closed" 21763 22113 21822 "Outpatient"
    4 "Closed" 21763 22120 21822 "Outpatient"
    4 "Closed" 21763 22127 21822 "Outpatient"
    4 "Closed" 21763 22130 21822 "Outpatient"
    4 "Closed" 21763 22147 21822 "Outpatient"
    4 "Closed" 21763 22148 21822 "Outpatient"
    4 "Closed" 21763 22160 21822 "Outpatient"
    4 "Closed" 21763 22182 21822 "Outpatient"
    4 "Closed" 21763 22189 21822 "Outpatient"
    4 "Closed" 21763 22190 21822 "Outpatient"
    4 "Closed" 21763 22190 21822 "Outpatient"
    4 "Closed" 21763 22195 21822 "Outpatient"
    4 "Closed" 21763 22201 21822 "Outpatient"
    4 "Closed" 21763 22203 21822 "Outpatient"
    4 "Closed" 21763 22204 21822 "Outpatient"
    4 "Closed" 21763 22217 21822 "Outpatient"
    4 "Closed" 21763 22231 21822 "Outpatient"
    4 "Closed" 21763 22249 21822 "Outpatient"
    4 "Closed" 21763 22249 21822 "Outpatient"
    4 "Closed" 21763 22252 21822 "Outpatient"
    4 "Closed" 21763 22257 21822 "Outpatient"
    4 "Closed" 21763 22266 21822 "Outpatient"
    4 "Closed" 21763 22285 21822 "Outpatient"
    4 "Closed" 21763 22294 21822 "Outpatient"
    4 "Closed" 21763 22294 21822 "Outpatient"
    4 "Closed" 21763 22299 21822 "Outpatient"
    4 "Closed" 21763 22306 21822 "Outpatient"
    4 "Closed" 21763 22308 21822 "Outpatient"
    4 "Closed" 21763 22315 21822 "Outpatient"
    4 "Closed" 21763 22319 21822 "Outpatient"
    4 "Closed" 21763 22319 21822 "Outpatient"
    4 "Closed" 21763 22320 21822 "Outpatient"
    4 "Closed" 21763 22327 21822 "Outpatient"
    4 "Closed" 21763 22329 21822 "Outpatient"
    4 "Closed" 21763 22335 21822 "Outpatient"
    4 "Closed" 21763 22337 21822 "Outpatient"
    4 "Closed" 21763 22343 21822 "Outpatient"
    4 "Closed" 21763 22344 21822 "Outpatient"
    4 "Closed" 21763 22344 21822 "Outpatient"
    4 "Closed" 21763 22350 21822 "Outpatient"
    4 "Closed" 21763 22356 21822 "Outpatient"
    4 "Closed" 21763 22357 21822 "Outpatient"
    4 "Closed" 21763 22357 21822 "Outpatient"
    4 "Closed" 21763 22363 21822 "Outpatient"
    4 "Closed" 21763 22368 21822 "Outpatient"
    4 "Closed" 21763 22368 21822 "Outpatient"
    4 "Closed" 21763 22371 21822 "Outpatient"
    4 "Closed" 21763 22375 21822 "Outpatient"
    4 "Closed" 21763 22378 21822 "Outpatient"
    4 "Closed" 21763 22379 21822 "Outpatient"
    4 "Closed" 21763 22379 21822 "Outpatient"
    4 "Closed" 21763 22384 21822 "Outpatient"
    4 "Closed" 21763 22385 21822 "Outpatient"
    4 "Closed" 21763 22389 21822 "Outpatient"
    4 "Closed" 21763 22389 21822 "Outpatient"
    4 "Closed" 21763 22398 21822 "Outpatient"
    4 "Closed" 21763 22398 21822 "Outpatient"
    4 "Closed" 21763 22404 21822 "Outpatient"
    4 "Closed" 21763 22404 21822 "Outpatient"
    4 "Closed" 21763 22407 21822 "Outpatient"
    4 "Closed" 21763 22407 21822 "Outpatient"
    4 "Closed" 21763 22425 21822 "Outpatient"
    4 "Closed" 21763 22434 21822 "Outpatient"
    4 "Closed" 21763 22459 21822 "Outpatient"
    4 "Closed" 21763 22461 21822 "Outpatient"
    4 "Closed" 21763 22462 21822 "Outpatient"
    4 "Closed" 21763 22463 21822 "Outpatient"
    4 "Closed" 21763 22467 21822 "Outpatient"
    4 "Closed" 21763 22467 21822 "Outpatient"
    4 "Closed" 21763 22468 21822 "Outpatient"
    4 "Closed" 21763 22477 21822 "Outpatient"
    4 "Closed" 21763 22481 21822 "Outpatient"
    4 "Closed" 21763 22490 21822 "Outpatient"
    4 "Closed" 21763 22491 21822 "Outpatient"
    4 "Closed" 21763 22495 21822 "Outpatient"
    4 "Closed" 21763 22496 21822 "Outpatient"
    4 "Closed" 21763 22509 21822 "Outpatient"
    4 "Closed" 21763 22510 21822 "Outpatient"
    4 "Closed" 21763 22510 21822 "Outpatient"
    4 "Closed" 21763 22519 21822 "Outpatient"
    4 "Closed" 21763 22526 21822 "Outpatient"
    4 "Closed" 21763 22533 21822 "Outpatient"
    4 "Closed" 21763 22544 21822 "Outpatient"
    4 "Closed" 21763 22552 21822 "Outpatient"
    4 "Closed" 21763 22553 21822 "Outpatient"
    4 "Closed" 21763 22558 21822 "Outpatient"
    4 "Closed" 21763 22565 21822 "Outpatient"
    4 "Closed" 21763 22565 21822 "Outpatient"
    4 "Closed" 21763 22572 21822 "Outpatient"
    4 "Closed" 21763 22572 21822 "Outpatient"
    4 "Closed" 21763 22579 21822 "Outpatient"
    4 "Closed" 21763 22579 21822 "Outpatient"
    4 "Closed" 21763 22581 21822 "Outpatient"
    4 "Closed" 21763 22585 21822 "Outpatient"
    4 "Closed" 21763 22588 21822 "Outpatient"
    4 "Closed" 21763 22588 21822 "Outpatient"
    4 "Closed" 21763 22588 21822 "Outpatient"
    4 "Closed" 21763 22588 21822 "Outpatient"
    4 "Closed" 21763 22601 21822 "Outpatient"
    4 "Closed" 21763 22616 21822 "Outpatient"
    4 "Closed" 21763 22616 21822 "Outpatient"
    4 "Closed" 21763 22620 21822 "Outpatient"
    4 "Closed" 21763 22624 21822 "Outpatient"
    4 "Closed" 21763 22627 21822 "Outpatient"
    4 "Closed" 21763 22644 21822 "Outpatient"
    4 "Closed" 21763 22645 21822 "Outpatient"
    4 "Closed" 21763 22649 21822 "Outpatient"
    4 "Closed" 21763 22652 21822 "Outpatient"
    4 "Closed" 21763 22663 21822 "Outpatient"
    4 "Closed" 21763 22663 21822 "Outpatient"
    4 "Closed" 21763 22669 21822 "Outpatient"
    4 "Closed" 21763 22669 21822 "Outpatient"
    4 "Closed" 21763 22671 21822 "Outpatient"
    4 "Closed" 21763 22671 21822 "Outpatient"
    4 "Closed" 21763 22673 21822 "Outpatient"
    4 "Closed" 21763 22676 21822 "Outpatient"
    4 "Closed" 21763 22676 21822 "Outpatient"
    4 "Closed" 21763 22678 21822 "Outpatient"
    4 "Closed" 21763 22678 21822 "Outpatient"
    4 "Closed" 21763 22679 21822 "Outpatient"
    4 "Closed" 21763 22682 21822 "Outpatient"
    4 "Closed" 21763 22686 21822 "Outpatient"
    4 "Closed" 21763 22686 21822 "Outpatient"
    4 "Closed" 21763 22690 21822 "Outpatient"
    4 "Closed" 21763 22692 21822 "Outpatient"
    4 "Closed" 21763 22707 21822 "Outpatient"
    4 "Closed" 21763 22712 21822 "Outpatient"
    4 "Closed" 21763 22714 21822 "Outpatient"
    4 "Closed" 21763 22719 21822 "Outpatient"
    4 "Closed" 21763 22721 21822 "Outpatient"
    4 "Closed" 21763 22726 21822 "Outpatient"
    4 "Closed" 21763 22732 21822 "Outpatient"
    4 "Closed" 21763 22732 21822 "Outpatient"
    4 "Closed" 21763 22732 21822 "Outpatient"
    4 "Closed" 21763 22741 21822 "Outpatient"
    4 "Closed" 21763 22741 21822 "Outpatient"
    4 "Closed" 21763 22760 21822 "Outpatient"
    4 "Closed" 21763 22760 21822 "Outpatient"
    4 "Closed" 21763 22760 21822 "Outpatient"
    4 "Closed" 21763 22776 21822 "Outpatient"
    4 "Closed" 21763 22781 21822 "Outpatient"
    4 "Closed" 21763 22789 21822 "Outpatient"
    4 "Closed" 21763 22789 21822 "Outpatient"
    4 "Closed" 21763 22796 21822 "Outpatient"
    4 "Closed" 21763 22818 21822 "Outpatient"
    4 "Closed" 21763 22823 21822 "Outpatient"
    4 "Closed" 21763 22823 21822 "Outpatient"
    4 "Closed" 21763 22824 21822 "Outpatient"
    4 "Closed" 21763 22831 21822 "Outpatient"
    4 "Closed" 21763 22831 21822 "Outpatient"
    4 "Closed" 21763 22831 21822 "Outpatient"
    4 "Closed" 21763 22832 21822 "Outpatient"
    4 "Closed" 21763 22832 21822 "Outpatient"
    4 "Closed" 21763 22839 21822 "Outpatient"
    4 "Closed" 21763 22845 21822 "Outpatient"
    4 "Closed" 21763 22846 21822 "Outpatient"
    4 "Closed" 21763 22853 21822 "Outpatient"
    4 "Closed" 21763 22860 21822 "Outpatient"
    4 "Closed" 21763 22861 21822 "Outpatient"
    4 "Closed" 21763 22866 21822 "Outpatient"
    4 "Closed" 21763 22867 21822 "Outpatient"
    4 "Closed" 21763 22871 21822 "Outpatient"
    4 "Closed" 21763 22873 21822 "Outpatient"
    4 "Closed" 21763 22901 21822 "Outpatient"
    4 "Closed" 21763 22902 21822 "Outpatient"
    4 "Closed" 21763 22902 21822 "Outpatient"
    4 "Closed" 21763 22902 21822 "Outpatient"
    4 "Closed" 21763 22903 21822 "Outpatient"
    4 "Closed" 21763 22916 21822 "Inpatient" 
    4 "Closed" 21763 22916 21822 "Inpatient" 
    4 "Closed" 21763 22930 21822 "Inpatient" 
    4 "Closed" 21763 22931 21822 "Inpatient" 
    4 "Closed" 21763 22931 21822 "Inpatient" 
    4 "Closed" 21763 22938 21822 "Inpatient" 
    4 "Closed" 21763 22939 21822 "Inpatient" 
    4 "Closed" 21763 22944 21822 "Inpatient" 
    4 "Closed" 21763 22951 21822 "Inpatient" 
    4 "Closed" 21763 22951 21822 "Inpatient" 
    4 "Closed" 21763 22951 21822 "Inpatient" 
    4 "Closed" 21763 22953 21822 "Inpatient" 
    4 "Closed" 21763 22958 21822 "Inpatient" 
    4 "Closed" 21763 22965 21822 "Inpatient" 
    4 "Closed" 21763 22965 21822 "Inpatient" 
    4 "Closed" 21763 22972 21822 "Outpatient"
    4 "Closed" 21763 22979 21822 "Outpatient"
    4 "Closed" 21763 22979 21822 "Outpatient"
    4 "Closed" 21763 22986 21822 "Outpatient"
    4 "Closed" 21763 22993 21822 "Outpatient"
    4 "Closed" 21763 23000 21822 "Outpatient"
    4 "Closed" 21763 23001 21822 "Outpatient"
    4 "Closed" 21763 23007 21822 "Outpatient"
    4 "Closed" 21763 23014 21822 "Outpatient"
    5 "Closed" 21763 23021 21822 "Inpatient" 
    5 "Closed" 21763 23030 21822 "Inpatient" 
    5 "Closed" 21763 23037 21822 "Inpatient" 
    5 "Closed" 21763 23040 21822 "Inpatient" 
    5 "Closed" 21763 23041 21822 "Inpatient" 
    5 "Closed" 21763 23041 21822 "Inpatient" 
    5 "Closed" 21763 23049 21822 "Inpatient" 
    5 "Closed" 21763 23057 21822 "Inpatient" 
    5 "Closed" 21763 23065 21822 "Inpatient" 
    5 "Closed" 21763 23065 21822 "Inpatient" 
    5 "Closed" 22358 21473 22463 "Inpatient" 
    5 "Closed" 22358 21494 22463 "Inpatient" 
    5 "Closed" 22358 21503 22463 "Inpatient" 
    5 "Closed" 22358 21521 22463 "Inpatient" 
    5 "Closed" 22358 21529 22463 "Outpatient"
    5 "Closed" 22358 21530 22463 "Outpatient"
    5 "Closed" 22358 21545 22463 "Outpatient"
    5 "Closed" 22358 21553 22463 "Outpatient"
    5 "Closed" 22358 21587 22463 "Outpatient"
    5 "Closed" 22358 21587 22463 "Outpatient"
    5 "Closed" 22358 21601 22463 "Outpatient"
    5 "Closed" 22358 21605 22463 "Outpatient"
    5 "Closed" 22358 21608 22463 "Outpatient"
    5 "Closed" 22358 21612 22463 "Outpatient"
    5 "Closed" 22358 21626 22463 "Outpatient"
    5 "Closed" 22358 21640 22463 "Outpatient"
    5 "Closed" 22358 21655 22463 "Outpatient"
    end
    format %tdnn/dd/CCYY enrollmentdate
    format %tdnn/dd/CCYY servicedate
    format %tdnn/dd/CCYY dischargeddate


    Any help beyond this would be greatly appreciated! Thank you!

Working...
X