library(Statamarkdown)

The following indices are preliminary results to be presented on SER 2020. We used a dataset in construction, in which many cases had to be discarded in order to produce valid estimates. However, we are still working to rescue as much valid treatments and patients as possible.

  • We eliminated cases without an available date of discharge or date of admission
  • We eliminated repeated events due to the combination of HASHs and dates of admission.
  • We eliminated cases with negative days of treatment
  • We eliminated cases that doesn’t followed the criteria proposed by SENDA’s Professionals (eg., programs that were not payed by SENDA or programs for parole)

This survival setting selected the first events from each HASH, The event is defined by being readmitted one or more times between 2010 to 2019.

Person days are concieved as the difference in each HASH, of the minimum date of admission (the first time that each patient was admitted between 2010 and 2019), and the maximum date of discharge (the last time that a patient was discharged from a treatment between 2010 and 2019).

qui use "G:\Mi unidad\Alvacast\SISTRAT 2019 (github)\Stata SER 2020\_CONS_C1_df_csv_pedido_SER2020_avance6(ENE 2020).dta", clear
* cases with only one event are  keeped
* dup= count how many times the hash has repeated (eg. 1, 2,  3)
* duplicates_filtered= count the total times each hash has repeated, different than duplicated_hash because this may be considering deleted cases. 
* get the first case if there are no other among them
qui gen a_botar=.
qui recode a_botar .=1 if dup==0 & duplicates_filtered==1
qui recode a_botar .=1 if dup==1 & duplicates_filtered>1
qui drop if missing(a_botar)
qui gen event=0
qui recode event 0=1 if dup>0
qui stset person_days, failure(event==1) scale(365.25) id(row)
stdescribe, weight
*always get the first treatment, if it has more than one: 
*get the first case if there are no other among them
******browse hash_key a_botar dup duplicates_filtered if dup==0 & duplicates_filtered ==1
******browse hash_key a_botar dup duplicates_filtered if duplicates_filtered >1
****drop unique cases
drop if missing(a_botar)
****generate event if each hash has more than one admission
> df_csv_pedido_SER2020_avance6(ENE 2020).dta", clear

         failure _d:  event == 1
   analysis time _t:  person_days/365.25
                 id:  row

                                   |-------------- per subject --------------|
Category                   total        mean         min     median        max
------------------------------------------------------------------------------
no. of subjects            76584   
no. of records             76584           1           1          1          1

(first) entry time                         0           0          0          0
(final) exit time                   1.172595    .0027379   .6105407   11.91239

subjects with gap              0   
time on gap if gap             0           .           .          .          .
time at risk           89802.045    1.172595    .0027379   .6105407   11.91239

failures                   17832    .2328424           0          0          1
------------------------------------------------------------------------------

(0 observations deleted)


Then, we set the dataset as a survival time format, configured by years (365.25 days) and defined by the difference between the last date of discharge of the last treatment and the date of admission of the following treatment (person_days) along the datasets from 2010 to 2019.

Of the subjects, had more than one treatment.

qui stsum
qui file open myfile using example_c.txt, write replace
qui file write myfile `"`r(ir)'"'
qui file close myfile

We calculated the failures in single-failre-per-subject data, divided by the total analysis time at risk and under observation. The cumulative incidence rate of readmission was 198.6 (per 1,000 patients/year).

Incidence Rate By Groups

We recoded the variables of cause of discharge, in order to account for early drop-out and late drop-out.

qui recode motivodeegreso   (1=.  ) ///
                        (2=3  "Alta Administrativa") ///
                        (3=4 "Alta Terap?utica") ///
                        (4=5 "Derivaci?n"), gen(mot_egreso_rec)
qui recode mot_egreso_rec .=1 if earlywdl==1
qui recode mot_egreso_rec .=2 if earlywdl==0

qui label define mot_egreso_rec 1 "Abandono Temprano", modify
qui label define mot_egreso_rec 2 "Abandono Tardio", modify

qui recode mot_egreso_rec   (4=0 "Alta Terap?utica") ///
                        (1=1 "Abandono Temprano") (else=.), gen(mot_egres_earlywdl)
qui tab mot_egreso_rec mot_egres_earlywdl, miss

qui recode mot_egreso_rec   (4=0 "Alta Terap?utica") ///
                        (2=1 "Abandono Tard?o") (else=.), gen(mot_egres_latewdl)
qui tab mot_egreso_rec mot_egres_latewdl, miss
>                                                 (2=3  "Alta Administrativa") 
> ///
>                                                 (3=4 "Alta Terap?utica") ///
>                                                 (4=5 "Derivaci?n"), gen(mot_e
> greso_rec)

Compared with those with therapeutic discharge, it was 2.85 [IC95% 2.69- 3.01] times higher among people with early drop-out,

Compared with those with therapeutic discharge, it was 1.72 [IC95% 1.64- 1.80] times higher among people with late drop-out.


We recoded the variables of main type of drug, in order to account for the main substance and comparisons between them: Cocaine vs. Alcohol, Cocaine Paste vs. Alcohol, and Marihuana vs. Alcohol.

qui recode droga (1=1  "Cocaina") ///
             (2=2  "Alcohol") ///
             (3=3 "Marihuana") ///
             (7=4 "Pasta Base") ///
             (4 5 6 8 9 10=5 "Otros"), gen(droga_rec)

qui recode droga (1=1  "Cocaina") ///
             (2=0 "Alcohol" ) ///
             (3=. ) ///
             (7=. ) ///
             (4 5 6 8 9 10=. ), gen(droga_rec_coc)
qui recode droga (1=.  ) ///
             (2=0  "Alcohol") ///
             (3=. ) ///
             (7=1 "Pasta Base") ///
             (4 5 6 8 9 10=. ), gen(droga_rec_pbase)
qui recode droga (1=.  ) ///
             (2=0 "Alcohol") ///
             (3=1 "Marihuana") ///
             (7=. ) ///
             (4 5 6 8 9 10=. ), gen(droga_rec_mar)
>                          (2=2  "Alcohol") ///
>                          (3=3 "Marihuana") ///
>                          (7=4 "Pasta Base") ///
>                          (4 5 6 8 9 10=5 "Otros"), gen(droga_rec)

Compared with those with alcohol as the main substance at admission, the cumulative incidence rate of readmission was 1.28 [IC95% 1.22- 1.34] times higher for those using cocaine.

Compared with those with alcohol as the main substance at admission, the cumulative incidence rate of readmission was 1.53 [IC95% 1.47- 1.58] times higher for those using cocaine paste.

Compared with those with alcohol as the main substance at admission, there were not important differences in the cumulative incidence for those using marijuana (1.03 [IC95% 0.96- 1.10]).

Incidence Rate Graphics

The following figures shows the Nelson-Aalen for the cumulative hazard of experiencing readmission in the study period.

In order to graphic the differences between Early drop-out and Therapeutic Discharge on a time span, we had to set the dataset in a format that let us capture the first readmission.

*ytitle("Prob. of Being Readmitted") 
*"it measures the total amount of risk that has been accumulated up to time t" (p. 8)
*count data interpretation: "it gives the number of times we would expect (mathematically) to observe failures [or other events] over a given period, if only the failure event were repeatable" (p. 13)
*https://books.google.de/books?id=xttbn0a-QR8C&printsec=frontcover&hl=de#v=onepage&q&f=false
sts graph, by (mot_egres_earlywdl) na ci title("Cumulative Hazard to Experience Readmission to" "SUD Treatment, by cause of Discharge") /// 
subtitle("Nelson-Aalen Estimator w/ Confidence Intervals 95%") ///
ylabel(#8) ///
risktable(, size(*.5) order(1 "Therapeutic Discharge" 2 "Early drop-out")) ///
xtitle("Years Follow-up") xlabel(#8) ///
note("Source: FONDECYT 1191282, SENDA's SUD Treatments period 2010-2019") ///
legend(rows(3)) ///
legend(cols(4)) ///
graphregion(color(white) lwidth(large)) bgcolor(white) ///
plotregion(fcolor(white)) graphregion(fcolor(white) ) ///
legend(order(1 "95% CI Therapeutic Discharge" 2 "Therapeutic Discharge" 3 "95% CI Early drop-out" 4 "Early drop-out")size(*.5)region(lstyle(none)) region(c(none)) nobox) 
*graph export "G:\Mi unidad\Alvacast\SISTRAT 2019 (github)\SUD_CL\stata1.svg", as(svg) width(800) height(600) replace
         failure _d:  event == 1
   analysis time _t:  person_days/365.25
                 id:  row
(note:  named style large not found in class linewidth, default attributes
    used)
(note:  linewidth not found in scheme, default attributes used)
(note:  named style large not found in class linewidth, default attributes
    used)
(note:  linewidth not found in scheme, default attributes used)
knitr::include_graphics("G:/Mi unidad/Alvacast/SISTRAT 2019 (github)/SUD_CL/stata1.svg")

sts graph, by (mot_egres_latewdl) na ci title("Cumulative Hazard to Experience Readmission to" "SUD Treatment by cause of Discharge") /// 
subtitle("Nelson-Aalen Estimator w/ Confidence Intervals 95%") ///
risktable(, size(*.5) order(1 "Therapeutic Discharge" 2 "Late drop-out")) ///
ylabel(#8) ///
xtitle("Years Follow-up") xlabel(#8) ///
note("Source: FONDECYT 1191282, SENDA's SUD Treatments period 2010-2019") ///
legend(rows(3)) ///
legend(cols(4)) ///
graphregion(color(white) lwidth(large)) bgcolor(white) ///
plotregion(fcolor(white)) graphregion(fcolor(white) ) ///
legend(order(1 "95% CI Therapeutic Discharge" 2 "Therapeutic Discharge" 3 "95% CI Late drop-out" 4 "Late drop-out")size(*.5)region(lstyle(none)) region(c(none)) nobox) 
graph export "G:\Mi unidad\Alvacast\SISTRAT 2019 (github)\SUD_CL\stata2.svg", as(svg) width(800) height(600) replace
> e Readmission to" "SUD Treatment by cause of Discharge") /// 
> subtitle("Nelson-Aalen Estimator w/ Confidence Intervals 95%") ///
> risktable(, size(*.5) order(1 "Therapeutic Discharge" 2 "Late drop-out")) ///
> ylabel(#8) ///
> xtitle("Years Follow-up") xlabel(#8) ///
> note("Source: FONDECYT 1191282, SENDA's SUD Treatments period 2010-2019") ///
> legend(rows(3)) ///
> legend(cols(4)) ///
> graphregion(color(white) lwidth(large)) bgcolor(white) ///
> plotregion(fcolor(white)) graphregion(fcolor(white) ) ///
> legend(order(1 "95% CI Therapeutic Discharge" 2 "Therapeutic Discharge" 3 "95
> % CI Late drop-out" 4 "Late drop-out")size(*.5)region(lstyle(none)) region(c(
> none)) nobox) 

         failure _d:  event == 1
   analysis time _t:  person_days/365.25
                 id:  row
(note:  named style large not found in class linewidth, default attributes
    used)
(note:  linewidth not found in scheme, default attributes used)
(note:  named style large not found in class linewidth, default attributes
    used)
(note:  linewidth not found in scheme, default attributes used)

(file G:\Mi unidad\Alvacast\SISTRAT 2019 (github)\SUD_CL\stata2.svg written in 
> SVG format)
knitr::include_graphics("G:/Mi unidad/Alvacast/SISTRAT 2019 (github)/SUD_CL/stata2.svg")

sts graph, by (droga_rec_pbase) na ci  ///
title("Cumulative Hazard to Experience Readmission to" "SUD Treatment by Main Drug Consumed") /// 
subtitle("Nelson-Aalen Estimator w/ Confidence Intervals 95%") ///
risktable(, size(*.5) order(1 "Alcohol" 2 "P. Base" )) ///
ylabel(#8) ///
xtitle("Years Follow-up") xlabel(#8) ///
note("Source: FONDECYT 1191282, SENDA's SUD Treatments period 2010-2019") ///
legend(rows(3)) ///
legend(cols(4)) ///
graphregion(color(white) lwidth(large)) bgcolor(white) ///
plotregion(fcolor(white)) graphregion(fcolor(white) ) ///
legend(order(1 "95CI Alcohol" 2 "Alcohol" 3 "95CI P. Base" 4 "P. Base"  )size(*.5)region(lstyle(none)) region(c(none)) nobox)
graph export "G:\Mi unidad\Alvacast\SISTRAT 2019 (github)\SUD_CL\stata3.svg", as(svg) width(800) height(600) replace
> title("Cumulative Hazard to Experience Readmission to" "SUD Treatment by Main
>  Drug Consumed") /// 
> subtitle("Nelson-Aalen Estimator w/ Confidence Intervals 95%") ///
> risktable(, size(*.5) order(1 "Alcohol" 2 "P. Base" )) ///
> ylabel(#8) ///
> xtitle("Years Follow-up") xlabel(#8) ///
> note("Source: FONDECYT 1191282, SENDA's SUD Treatments period 2010-2019") ///
> legend(rows(3)) ///
> legend(cols(4)) ///
> graphregion(color(white) lwidth(large)) bgcolor(white) ///
> plotregion(fcolor(white)) graphregion(fcolor(white) ) ///
> legend(order(1 "95CI Alcohol" 2 "Alcohol" 3 "95CI P. Base" 4 "P. Base"  )size
> (*.5)region(lstyle(none)) region(c(none)) nobox)

         failure _d:  event == 1
   analysis time _t:  person_days/365.25
                 id:  row
(note:  named style large not found in class linewidth, default attributes
    used)
(note:  linewidth not found in scheme, default attributes used)
(note:  named style large not found in class linewidth, default attributes
    used)
(note:  linewidth not found in scheme, default attributes used)

(file G:\Mi unidad\Alvacast\SISTRAT 2019 (github)\SUD_CL\stata3.svg written in 
> SVG format)
knitr::include_graphics("G:/Mi unidad/Alvacast/SISTRAT 2019 (github)/SUD_CL/stata3.svg")

sts graph, by (droga_rec_mar) na ci ///
title("Cumulative Hazard to Experience Readmission to" "SUD Treatment by Main Drug Consumed") /// 
subtitle("Nelson-Aalen Estimator w/ Confidence Intervals 95%") ///
risktable(, size(*.5) order(1 "Alcohol" 2 "Marihuana")) ///
ylabel(#8) ///
xtitle("Years Follow-up") xlabel(#8) ///
note("Source: FONDECYT 1191282, SENDA's SUD Treatments period 2010-2019") ///
legend(rows(3)) ///
legend(cols(4)) ///
graphregion(color(white) lwidth(large)) bgcolor(white) ///
plotregion(fcolor(white)) graphregion(fcolor(white) ) ///
legend(order(1 "95CI Alcohol" 2 "Alcohol" 3 "95CI Marihuana" 4 "Marihuana"  )size(*.5)region(lstyle(none)) region(c(none)) nobox)
graph export "G:\Mi unidad\Alvacast\SISTRAT 2019 (github)\SUD_CL\stata4.svg", as(svg) width(800) height(600) replace
> title("Cumulative Hazard to Experience Readmission to" "SUD Treatment by Main
>  Drug Consumed") /// 
> subtitle("Nelson-Aalen Estimator w/ Confidence Intervals 95%") ///
> risktable(, size(*.5) order(1 "Alcohol" 2 "Marihuana")) ///
> ylabel(#8) ///
> xtitle("Years Follow-up") xlabel(#8) ///
> note("Source: FONDECYT 1191282, SENDA's SUD Treatments period 2010-2019") ///
> legend(rows(3)) ///
> legend(cols(4)) ///
> graphregion(color(white) lwidth(large)) bgcolor(white) ///
> plotregion(fcolor(white)) graphregion(fcolor(white) ) ///
> legend(order(1 "95CI Alcohol" 2 "Alcohol" 3 "95CI Marihuana" 4 "Marihuana"  )
> size(*.5)region(lstyle(none)) region(c(none)) nobox)

         failure _d:  event == 1
   analysis time _t:  person_days/365.25
                 id:  row
(note:  named style large not found in class linewidth, default attributes
    used)
(note:  linewidth not found in scheme, default attributes used)
(note:  named style large not found in class linewidth, default attributes
    used)
(note:  linewidth not found in scheme, default attributes used)

(file G:\Mi unidad\Alvacast\SISTRAT 2019 (github)\SUD_CL\stata4.svg written in 
> SVG format)
knitr::include_graphics("G:/Mi unidad/Alvacast/SISTRAT 2019 (github)/SUD_CL/stata4.svg")

sts graph, by (droga_rec_coc) na ci  ///
title("Cumulative Hazard to Experience Readmission to" "SUD Treatment by Main Drug Consumed") /// 
subtitle("Nelson-Aalen Estimator w/ Confidence Intervals 95%") ///
risktable(, size(*.5) order(1 "Alcohol" 2 "Cocaine")) ///
ylabel(#8) ///
xtitle("Years Follow-up") xlabel(#8) ///
note("Source: FONDECYT 1191282, SENDA's SUD Treatments period 2010-2019") ///
legend(rows(3)) ///
legend(cols(4)) ///
graphregion(color(white) lwidth(large)) bgcolor(white) ///
plotregion(fcolor(white)) graphregion(fcolor(white) ) ///
legend(order(1 "95CI Alcohol" 2 "Alcohol" 3 "95CI Cocaine" 4 "Cocaine" )size(*.5)region(lstyle(none)) region(c(none)) nobox)
graph export "G:\Mi unidad\Alvacast\SISTRAT 2019 (github)\SUD_CL\stata5.svg", as(svg) width(800) height(600) replace
> title("Cumulative Hazard to Experience Readmission to" "SUD Treatment by Main
>  Drug Consumed") /// 
> subtitle("Nelson-Aalen Estimator w/ Confidence Intervals 95%") ///
> risktable(, size(*.5) order(1 "Alcohol" 2 "Cocaine")) ///
> ylabel(#8) ///
> xtitle("Years Follow-up") xlabel(#8) ///
> note("Source: FONDECYT 1191282, SENDA's SUD Treatments period 2010-2019") ///
> legend(rows(3)) ///
> legend(cols(4)) ///
> graphregion(color(white) lwidth(large)) bgcolor(white) ///
> plotregion(fcolor(white)) graphregion(fcolor(white) ) ///
> legend(order(1 "95CI Alcohol" 2 "Alcohol" 3 "95CI Cocaine" 4 "Cocaine" )size(
> *.5)region(lstyle(none)) region(c(none)) nobox)

         failure _d:  event == 1
   analysis time _t:  person_days/365.25
                 id:  row
(note:  named style large not found in class linewidth, default attributes
    used)
(note:  linewidth not found in scheme, default attributes used)
(note:  named style large not found in class linewidth, default attributes
    used)
(note:  linewidth not found in scheme, default attributes used)

(file G:\Mi unidad\Alvacast\SISTRAT 2019 (github)\SUD_CL\stata5.svg written in 
> SVG format)
knitr::include_graphics("G:/Mi unidad/Alvacast/SISTRAT 2019 (github)/SUD_CL/stata5.svg")

Time outside treatment

To calculate the average time outside treatment, we needed to drop cases with only one treatment and keep those with more than one treatment.

clear all
qui use "G:\Mi unidad\Alvacast\SISTRAT 2019 (github)\Stata SER 2020\_CONS_C1_df_csv_pedido_SER2020_avance6(ENE 2020).dta", clear
qui gen a_botar=.
qui recode a_botar .=1 if dup==0 & duplicates_filtered==1
qui drop if a_botar==1
des,short
Contains data from G:\Mi unidad\Alvacast\SISTRAT 2019 (github)\Stata SER 2020\_
> CONS_C1_df_csv_pedido_SER2020_avance6(ENE 2020).dta
  obs:        44,917                          
 vars:           133                          21 Jan 2020 13:31
Sorted by: hash_key  fech_ing_num
     Note: Dataset has changed since last saved.

Then, we had to order the dataset by HASHs and date of admission and date of discarge, and replace the date of discharge if it is greater than the next date of admission.

qui gsort hash_key fech_ing_fmt fech_egres_fmt
*si la fecha de  egreso es mayor a la siguiente fecha de ingreso, reemplazar con la fecha de ingreso
qui by hash_key: gen fech_egres_fmt_corr = fech_ing_fmt[_n+1] if fech_egres_fmt>fech_ing_fmt[_n+1]  
*si se quiere, replace
qui by hash_key: replace fech_egres_fmt = fech_ing_fmt[_n+1] if fech_egres_fmt>fech_ing_fmt[_n+1]  
**formatear
qui format fech_egres_fmt_corr %td
qui format fech_ing_fmt %td

Finally, we get the difference between the most recent date of admission and the next date of discharge (or lagged date). For example, if a patient X had 4 treatments, and among them, in the second treatment he/she was discharged in January 27, and the third treatment was admitted from March 30. Time span will be the 62 days.

*We iteratively stablished differences between times 
*get the time span between the date of admission and date of discharge
bysort hash_key (fech_ing_num): gen time5 = fech_egres_fmt - fech_ing_fmt[_n-1]
bysort hash_key (fech_ing_num): gen span_treat_days = fech_egres_fmt - fech_ing_fmt[_n-1]
*bysort hash_key (fech_ing_num): gen time6  = time5 - time[_n-1]  
gen span_treat= time5/365.25
*rename time5 span_treat
cd  "G:\Mi unidad\Alvacast\SISTRAT 2019 (github)\SUD_CL\"
hist span_treat_days,freq title(Histogram of Treatment Span) xtitle(Days Between Treatments) scheme(s1mono)
graph export "G:\Mi unidad\Alvacast\SISTRAT 2019 (github)\SUD_CL\stata6.svg", as(svg) width(800) height(600) replace
(17,832 missing values generated)

(17,832 missing values generated)

(17,832 missing values generated)

G:\Mi unidad\Alvacast\SISTRAT 2019 (github)\SUD_CL

(bin=44, start=3, width=95.659091)

(file G:\Mi unidad\Alvacast\SISTRAT 2019 (github)\SUD_CL\stata6.svg written in 
> SVG format)
knitr::include_graphics("G:/Mi unidad/Alvacast/SISTRAT 2019 (github)/SUD_CL/stata6.svg")

cap drop if missing(span_treat)
qui sum span_treat

The average treatment span between treatment was 2.15 years, for every event in the dataset. However. Considering the question was made focusing in those readmitted to treatment, we needed to collapse the dataset by HASHs.

qui collapse (mean) avg_span_treat=span_treat, by(hash_key) 
qui sum avg_span_treat

Summarising by HASHs, the average treatment span between treatments among the readmitted (17,832) in years is around 2.32 years.

Go back to the main webpage