Database (step 6)

Date created: 10 May 2022.

Install commands that are unavailable or out of date.

. clear all

. *rnethelp "http://www.stata-journal.com/software/sj13-1/st0289/stjm.sthlp"
. 
. cap noi which predictms
C:\Users\CISS Fondecyt\ado\plus\p\predictms.ado
*! version 4.3.0 14mar2021 MJC

. if _rc==111 {
.         cap noi net install multistate, from("https://www.mjcrowther.co.uk/code/multistate") 
.         }

. cap noi which merlin
C:\Users\CISS Fondecyt\ado\plus\m\merlin.ado
*! version 2.0.2 19mar2021 MJC

. if _rc==111 {
.         cap noi net install merlin, from("https://www.mjcrowther.co.uk/code/merlin/") 
.         }

. cap noi which sumat
C:\Users\CISS Fondecyt\ado\plus\s\sumat.ado
*! Part of package matrixtools v. 0.25
*! Support: Niels Henrik Bruun, niels.henrik.bruun@gmail.com
*! 2021-01-03 toxl added

. if _rc==111 {
.         cap noi scc install matrixtools
.         }

. cap noi which estwrite
C:\Users\CISS Fondecyt\ado\plus\e\estwrite.ado
*! version 1.2.4 04sep2009
*! version 1.0.1 15may2007 (renamed from -eststo- to -estwrite-; -append- added)
*! version 1.0.0 29apr2005 Ben Jann (ETH Zurich)

. if _rc==111 {
.         cap noi ssc install estwrite
.         }       

.         
. cap noi which scurve_tvc
C:\Users\CISS Fondecyt\ado\plus\s\scurve_tvc.ado

. if _rc==111 {
.         cap noi net install st0458, from("http://www.stata-journal.com/software/sj16-4")
.         }

. cap noi which strmcure  
C:\Users\CISS Fondecyt\ado\plus\s\strmcure.ado
*! Version 4.0 31-Aug-2015

. if _rc==111 {
.         cap noi net install st0374_1, from ("http://www.stata-journal.com/software/sj18-2")
.         }

. cap noi which stjmgraph 
C:\Users\CISS Fondecyt\ado\plus\s\stjmgraph.ado
*! version 1.0.2 01Jun2011 MJC

. if _rc==111 {
.         cap noi net install st0289, from ("http://www.stata-journal.com/software/sj13-1")
.         }       

We need to obtain the file and the work folder.

. mata : st_numscalar("OK", direxists("/volumes/sdrive/data//"))

. if scalar(OK) == 1 {
.         cap noi cd "/volumes/sdrive/data//"
.         global pathdata "/volumes/sdrive/data//"
.         di "Location= ${pathdata}; Date: `c(current_date)', considering an OS `c(os)' for the user: `c(username)'"
. }

. else display "This file does not exist"
This file does not exist

. 
. mata : st_numscalar("OK", direxists("E:\Mi unidad\Alvacast\SISTRAT 2019 (github)\_mult_state_ags\"))

. if scalar(OK) == 1 {
.         cap noi cd "E:\Mi unidad\Alvacast\SISTRAT 2019 (github)\_mult_state_ags"
.         global pathdata "E:\Mi unidad\Alvacast\SISTRAT 2019 (github)\_mult_state_ags"
.         global pathdata2 "E:/Mi unidad/Alvacast/SISTRAT 2019 (github)/_mult_state_ags/"
.         di "Location= ${pathdata}; Date: `c(current_date)', considering an OS `c(os)' for the user: `c(username)'"
. }

. else display "This file does not exist"
This file does not exist

. 
. mata : st_numscalar("OK", direxists("G:\Mi unidad\Alvacast\SISTRAT 2019 (github)\_mult_state_ags\"))

. if scalar(OK) == 1 {
.         cap noi cd "G:\Mi unidad\Alvacast\SISTRAT 2019 (github)\_mult_state_ags"
.         global pathdata "G:\Mi unidad\Alvacast\SISTRAT 2019 (github)\_mult_state_ags"
.         global pathdata2 "G:/Mi unidad/Alvacast/SISTRAT 2019 (github)/_mult_state_ags/"
.         di "Location= ${pathdata}; Date: `c(current_date)', considering an OS `c(os)' for the user: `c(username)'"
. }

. else display "This file does not exist"
This file does not exist

.                 
. mata : st_numscalar("OK", direxists("C:\Users\CISS Fondecyt\Mi unidad\Alvacast\SISTRAT 2019 (github)\_mult_state_ags\"))

. if scalar(OK) == 1 {
.         cap noi cd "C:\Users\CISS Fondecyt\Mi unidad\Alvacast\SISTRAT 2019 (github)"
C:\Users\CISS Fondecyt\Mi unidad\Alvacast\SISTRAT 2019 (github)
.         global pathdata "C:\Users\CISS Fondecyt\Mi unidad\Alvacast\SISTRAT 2019 (github)\_mult_state_ags"
.         global pathdata2 "C:/Users/CISS Fondecyt/Mi unidad/Alvacast/SISTRAT 2019 (github)/_mult_state_ags/"
.         di "Location= ${pathdata}; Date: `c(current_date)', considering an OS `c(os)' for the user: `c(username)'"
Location= C:\Users\CISS Fondecyt\Mi unidad\Alvacast\SISTRAT 2019 (github)\_mult_state_ags; Date: 10 May 2022, considering an OS Windows for the user: CISS Fondecyt
. }

. else display "This file does not exist"

. 
. mata : st_numscalar("OK", direxists("C:\Users\andre\Desktop\_mult_state_ags\"))

. if scalar(OK) == 1 {
.         cap noi cd "C:\Users\andre\Desktop\_mult_state_ags"
.         global pathdata "C:\Users\andre\Desktop\_mult_state_ags"
.         global pathdata2 "C:/Users/andre/Desktop/_mult_state_ags/"
.         di "Location= ${pathdata}; Date: `c(current_date)', considering an OS `c(os)' for the user: `c(username)'"
. }

. else display "This file does not exist"
This file does not exist

. 
. mata : st_numscalar("OK", direxists("C:\Users\CISS Fondecyt\OneDrive\Documentos\"))

. if scalar(OK) == 1 {
.         cap noi cd "C:\Users\CISS Fondecyt\Mi unidad\Alvacast\SISTRAT 2019 (github)\_mult_state_ags"
C:\Users\CISS Fondecyt\Mi unidad\Alvacast\SISTRAT 2019 (github)\_mult_state_ags
.         global pathdata "C:\Users\CISS Fondecyt\Mi unidad\Alvacast\SISTRAT 2019 (github)\_mult_state_ags"
.         global pathdata2 "C:/Users/CISS Fondecyt/Mi unidad/Alvacast/SISTRAT 2019 (github)/_mult_state_ags/"
.         di "Location= ${pathdata}; Date: `c(current_date)', considering an OS `c(os)' for the user: `c(username)'"
Location= C:\Users\CISS Fondecyt\Mi unidad\Alvacast\SISTRAT 2019 (github)\_mult_state_ags; Date: 10 May 2022, considering an OS Windows for the user: CISS Fondecyt
. }

. else display "This file does not exist"

. 

Path data= C:\Users\CISS Fondecyt\Mi unidad\Alvacast\SISTRAT 2019 (github)_mult_state_ags;

Timestamp: 10 May 2022, considering that is a Windows OS for the username: CISS Fondecyt

The file is located and named as: C:/Users/CISS Fondecyt/Mi unidad/Alvacast/SISTRAT 2019 (github)/_mult_state_ags/archivo_multiestado2_jun_22.dta

=============================================================================

PWP-TT

=============================================================================

. **https://europepmc.org/articles/PMC5805119/bin/qcx015_supp.pdf
. cap qui use "${pathdata2}five_st_msprep_apr22.dta", clear       

. matrix mat_five_states = (.,1,.,.,. \ .,.,2,.,. \.,.,.,3,. \.,.,.,.,4 \.,.,.,.,.)

. msset, id(id) states(Readmission_status Readmission2_status Readmission3_status Readmission4_status) ///
>                 times(Readmission_time Readmission2_time Readmission3_time Readmission4_time) transmatrix(mat_five_states)  //* saqué tipo_de_plan_res_1 para que no se empie
> ce a subdividir

. gen time = _stop - _start

. *originally i set this:
. stset _stop, fail(_status) exit(time .) id(id) enter(_start)

                id:  id
     failure event:  _status != 0 & _status < .
obs. time interval:  (_stop[_n-1], _stop]
 enter on or after:  time _start
 exit on or before:  time .

------------------------------------------------------------------------------
     31,455  total observations
          0  exclusions
------------------------------------------------------------------------------
     31,455  observations remaining, representing
     22,452  subjects
      9,203  failures in multiple-failure-per-subject data
   43733824  total analysis time at risk and under observation
                                                at risk from t =         0
                                     earliest observed entry t =         0
                                          last observed exit t =     4,592

. 
. *This is the correct stset for discontinuous risk intervals
. *b)* Prentice, Williams and Peterson Total Time (PWP-TT)
. *****Events are ordered and handled by stratification
. *****The PWP models are conditional models
. *****Everyone is at risk for the first stratum, but only who had
. ********an event in the previous stratum are at risk for the
. ********successive one
. *****It can estimate both overall and event-specific effects
. *****It uses robust standard errors to account for correlation
. ********(variance-corrected method)
. 
. *#Using counting process data structure the PWP-TT model may be fit using:
. *The nohr option can be used with stcox command to request estimated coefficients, instead of hazard ratios. The robust option produces a robust sandwich estimate for covari
> ance matrix. The exit time option defines the time when a subject stops being at risk. For multivariate survival data, in particular, it needs to be specified as exit(time .
> ) because the default procedure is to remove the subject from the risk set after the first failure.
. *In our case, it is no necessit to specify exit(time .)
. 
. stcox  tipo_de_plan_res_1 TD_1 TD_2 TD_3 TD_4, efron robust nolog strata(_trans) schoenfeld(sch*) scaledsch(sca*)

         failure _d:  _status
   analysis time _t:  _stop
  enter on or after:  time _start
  exit on or before:  time .
                 id:  id

Stratified Cox regr. -- Efron method for ties

No. of subjects      =          635             Number of obs    =       2,540
No. of failures      =        2,105
Time at risk         =      1584304
                                                Wald chi2(5)     =       42.81
Log pseudolikelihood =   -10696.782             Prob > chi2      =      0.0000

                                         (Std. Err. adjusted for 635 clusters in id)
------------------------------------------------------------------------------------
                   |               Robust
                _t | Haz. Ratio   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------------+----------------------------------------------------------------
tipo_de_plan_res_1 |    1.11682   .0527107     2.34   0.019     1.018143     1.22506
              TD_1 |   .7848313   .0411211    -4.62   0.000     .7082356    .8697108
              TD_2 |   .8904262     .05049    -2.05   0.041     .7967684    .9950931
              TD_3 |   .8310685   .0446395    -3.45   0.001     .7480246    .9233317
              TD_4 |    1.08848   .0601888     1.53   0.125       .97668    1.213078
------------------------------------------------------------------------------------
                                                          Stratified by _trans

. estat phtest, log detail

      Test of proportional-hazards assumption

      Time:  Log(t)
      ----------------------------------------------------------------
                  |       rho            chi2       df       Prob>chi2
      ------------+---------------------------------------------------
      tipo_de_pl~1|     -0.02712         1.65        1         0.1991
      TD_1        |      0.14029        34.90        1         0.0000
      TD_2        |      0.01740         0.62        1         0.4321
      TD_3        |      0.01672         0.53        1         0.4656
      TD_4        |     -0.00606         0.07        1         0.7879
      ------------+---------------------------------------------------
      global test |                     36.88        5         0.0000
      ----------------------------------------------------------------

note: robust variance-covariance matrix used.

. 
. *When to use it
. *****When the effects of covariates are different in subsequent events
. *****When the occurrence of the first event increases the likelihood of a recurrence
. *****When there are few recurrent events per subject
. 
. *****PWP-TT models could significantly underestimate the
. **********overall effect if there is no strong biological relationship
. **********between events
. 
. *****Thus, those methods could be proper for only handling a small number of
. **********recurrent events.
. 
. *c)* Prentice, Williams and Peterson Gap Time (PWP-GT)
. *In the PWP-TT model the time scale is time t, from beginning of study
. *In the PWP-GT model the time scale is time t, from the previous event
. 
. *Stratified Cox regr. -- Efron method for ties == efron

We checked the proportionality of hazards visually

. graph combine "${pathdata}\stphplot_trans_1_22.gph" "${pathdata}\stphplot_trans_2_22.gph" "${pathdata}\stphplot_trans_3_22.gph" "${pathdata}\stphplot_trans_4_22.gph", ///
> colfirst ycommon xcommon iscale(*.7) imargin(tiny) graphregion(color(gs16)) ///
> title("Combination of −ln{−ln(survival)} vs. ln(analysis time)" "PWP-TT", size(medium)) cols(2) ///
> note("{it:Note: Ordered by columns, from up to down, left to right;}" "{it:means and 95% CI's; Bandwidth=.8; Natural log of analysis time}", size(tiny)) ///
> l1(Schoenfeld residuals, size(medium)) b1("Log Time since admission (days)", size(medium)) ///
>         name(_trans_ph_ln_surv_time_22, replace)

.         
. local num 1 2 4

. foreach i of local num {
  2. gr_edit .plotregion1.graph`i'.legend.draw_view.setstyle, style(no)
  3. }

. 
. forvalues i = 1/4 {
  2. gr_edit .plotregion1.graph`i'.yaxis1.style.editstyle majorstyle(tickstyle(textstyle(size(medium)))) editcopy
  3. gr_edit .plotregion1.graph`i'.yaxis1.style.editstyle majorstyle(tickstyle(textgap(zero))) editcopy
  4. gr_edit .plotregion1.graph`i'.yaxis1.style.editstyle majorstyle(tickstyle(textgap(zero))) editcopy
  5. 
. gr_edit .plotregion1.graph`i'.xaxis1.style.editstyle majorstyle(tickstyle(textstyle(size(medium)))) editcopy
  6. gr_edit .plotregion1.graph`i'.xaxis1.style.editstyle majorstyle(tickstyle(textgap(zero))) editcopy
  7. gr_edit .plotregion1.graph`i'.xaxis1.style.editstyle majorstyle(use_labels(no)) editcopy
  8. *gr_edit .plotregion1.graph`i'.xaxis1.style.editstyle majorstyle(alternate(yes)) editcopy
. }

. 
. forvalues i = 1/4 {
  2. gr_edit .plotregion1.graph`i'.yaxis1.title.draw_view.setstyle, style(no)
  3. gr_edit .plotregion1.graph`i'.xaxis1.title.draw_view.setstyle, style(no)
  4. }

. 
. graph export "_tr_ph_ln_srv_time_22.png", as(png) replace width(2000) height(1000)
(file _tr_ph_ln_srv_time_22.png written in PNG format)

. graph export "_tr_ph_ln_srv_time_22.pdf", as(pdf) replace //*width(2000) height(2000) orientation(landscape)
(file _tr_ph_ln_srv_time_22.pdf written in PDF format)

Explored schoenfeld residuals:

. drop sch* sca*

. stcox  i.tipo_de_plan_res_1 i.TD_1 i.TD_2 i.TD_3 i.TD_4, efron robust nolog strata(_trans) schoenfeld(sch*) scaledsch(sca*)

         failure _d:  _status
   analysis time _t:  _stop
  enter on or after:  time _start
  exit on or before:  time .
                 id:  id

Stratified Cox regr. -- Efron method for ties

No. of subjects      =          635             Number of obs    =       2,540
No. of failures      =        2,105
Time at risk         =      1584304
                                                Wald chi2(5)     =       42.81
Log pseudolikelihood =   -10696.782             Prob > chi2      =      0.0000

                                           (Std. Err. adjusted for 635 clusters in id)
--------------------------------------------------------------------------------------
                     |               Robust
                  _t | Haz. Ratio   Std. Err.      z    P>|z|     [95% Conf. Interval]
---------------------+----------------------------------------------------------------
1.tipo_de_plan_res_1 |    1.11682   .0527107     2.34   0.019     1.018143     1.22506
              1.TD_1 |   .7848313   .0411211    -4.62   0.000     .7082356    .8697108
              1.TD_2 |   .8904262     .05049    -2.05   0.041     .7967684    .9950931
              1.TD_3 |   .8310685   .0446395    -3.45   0.001     .7480246    .9233317
              1.TD_4 |    1.08848   .0601888     1.53   0.125       .97668    1.213078
--------------------------------------------------------------------------------------
                                                          Stratified by _trans

. 
. estat phtest, log plot(1.tipo_de_plan_res_1) yline(0) msym(oh) ///
>          xtitle("Time (days)", size(small)) ///
>         xlabel(0(1460)5000, labsize(vsmall)) ///        
>         ylabel(-4(1)4, labsize(vsmall)) ///     
>         ytitle("Schoenfeld residuals", size(small)) scheme(sj) graphregion(color(white)) ///
>         note("{it:Note. Means and 95% CI's; Bandwidth=.8; Natural log of analysis time used.}",size(vsmall)) ///
>         title("Plot of scaled Schoenfeld residuals versus" "time produced for the covariate Treatment Modality", size(medium)) ///
>         subtitle("{it: specified by Running mean smoother}",size(small)) ///
>         name(phtest_log_plan_res_22, replace)  ///
>         saving(phtest_log_plan_res_22.gph, replace)
(file phtest_log_plan_res_22.gph saved)

. 
. forvalues i = 1/4 {
  2. gr_edit .plotregion1.graph`i'.title.draw_view.setstyle, style(no)
  3. }
phtest_log_plan_res_22..plotregion1.graph1.title.draw_view.setstyle, style(no): class type not found
r(4018);

. graph export "diff_probs_comb_sept_2022.png", as(png) replace width(2000) height(1000)
(file diff_probs_comb_sept_2022.png written in PNG format)

. graph export "diff_probs_comb_sept_2022.pdf", as(pdf) replace //*width(2000) height(2000) orientation(landscape)
(file diff_probs_comb_sept_2022.pdf written in PDF format)

. *graph export "_Appendix2_Graph_Mean_SE_g32.svg", as(svg) replace height(20000) fontface (Helvetica)
. graph save "diff_probs_comb_sept_2022", asis replace    
file diff_probs_comb_sept_2022.gph saved

. 
. ***The stphtest command with the plot option will provide the graphs with a lowess curve.  
. ***The usual graphing options can be used to include a horizontal reference line at y=0. 

. drop sch* sca*

. stcox  i.tipo_de_plan_res_1 i.TD_1 i.TD_2 i.TD_3 i.TD_4, efron robust nolog strata(_trans) schoenfeld(sch*) scaledsch(sca*)

         failure _d:  _status
   analysis time _t:  _stop
  enter on or after:  time _start
  exit on or before:  time .
                 id:  id

Stratified Cox regr. -- Efron method for ties

No. of subjects      =          635             Number of obs    =       2,540
No. of failures      =        2,105
Time at risk         =      1584304
                                                Wald chi2(5)     =       42.81
Log pseudolikelihood =   -10696.782             Prob > chi2      =      0.0000

                                           (Std. Err. adjusted for 635 clusters in id)
--------------------------------------------------------------------------------------
                     |               Robust
                  _t | Haz. Ratio   Std. Err.      z    P>|z|     [95% Conf. Interval]
---------------------+----------------------------------------------------------------
1.tipo_de_plan_res_1 |    1.11682   .0527107     2.34   0.019     1.018143     1.22506
              1.TD_1 |   .7848313   .0411211    -4.62   0.000     .7082356    .8697108
              1.TD_2 |   .8904262     .05049    -2.05   0.041     .7967684    .9950931
              1.TD_3 |   .8310685   .0446395    -3.45   0.001     .7480246    .9233317
              1.TD_4 |    1.08848   .0601888     1.53   0.125       .97668    1.213078
--------------------------------------------------------------------------------------
                                                          Stratified by _trans

. 
. estat phtest, log plot(1.TD_1) yline(0) msym(oh) ///
>          xtitle("Time (days)", size(small)) ///
>         xlabel(0(1460)5000, labsize(vsmall)) ///        
>         ylabel(-4(1)4, labsize(vsmall)) ///     
>         ytitle("Schoenfeld residuals", size(small)) scheme(sj) graphregion(color(white)) ///
>         note("{it:Note. Means and 95% CI's; Bandwidth=.8; Natural log of analysis time used.}",size(vsmall)) ///
>         title("Plot of scaled Schoenfeld residuals versus" "time produced for the covariate Treatment Completion", size(medium)) ///
>         subtitle("{it: specified by Running mean smoother}",size(small)) ///
>         name(phtest_log_TD_1_22, replace)  ///
>         saving(phtest_log_TD_1_22.gph, replace)
(file phtest_log_TD_1_22.gph saved)

. ***The stphtest command with the plot option will provide the graphs with a lowess curve.  
. ***The usual graphing options can be used to include a horizontal reference line at y=0. 

We included an interaction with time in the type of plan at baseline and in treatment completion at baseline

. *This interaction effect is best added using the tvc() and texp() options
. *https://static-content.springer.com/esm/art%3A10.1186%2F1475-2875-13-293/MediaObjects/12936_2014_3335_MOESM1_ESM.pdf
. stcox i.tipo_de_plan_res_1 i.TD_1 i.TD_2 i.TD_3 i.TD_4 _start , efron nolog robust strata(_trans) tvc(i.tipo_de_plan_res_1 i.TD_1)

         failure _d:  _status
   analysis time _t:  _stop
  enter on or after:  time _start
  exit on or before:  time .
                 id:  id


Stratified Cox regr. -- Efron method for ties

No. of subjects      =          635             Number of obs    =       2,540
No. of failures      =        2,105
Time at risk         =      1584304
                                                Wald chi2(8)     =       81.96
Log pseudolikelihood =   -10671.816             Prob > chi2      =      0.0000

                                           (Std. Err. adjusted for 635 clusters in id)
--------------------------------------------------------------------------------------
                     |               Robust
                  _t | Haz. Ratio   Std. Err.      z    P>|z|     [95% Conf. Interval]
---------------------+----------------------------------------------------------------
main                 |
1.tipo_de_plan_res_1 |   1.200592   .1049402     2.09   0.036     1.011567     1.42494
              1.TD_1 |   .4598424   .0537062    -6.65   0.000     .3657589    .5781268
              1.TD_2 |   .8983068   .0502609    -1.92   0.055     .8050066    1.002421
              1.TD_3 |   .8272533   .0435026    -3.61   0.000     .7462366    .9170657
              1.TD_4 |   1.100042   .0595428     1.76   0.078     .9893177    1.223159
              _start |   .9997052   .0000685    -4.30   0.000     .9995709    .9998395
---------------------+----------------------------------------------------------------
tvc                  |
1.tipo_de_plan_res_1 |   .9999307   .0000631    -1.10   0.272      .999807    1.000054
              1.TD_1 |   1.000436   .0000754     5.78   0.000     1.000288    1.000584
--------------------------------------------------------------------------------------
                                                          Stratified by _trans
Note: Variables in tvc equation interacted with _t.

. estimates store m3_pwptt

. estwrite _all using "${pathdata2}parmodels_m3_apr22.sters", append
(appending m3_pwptt)
(file C:/Users/CISS Fondecyt/Mi unidad/Alvacast/SISTRAT 2019 (github)/_mult_state_ags/parmodels_m3_apr22.sters saved)

. 

=============================================================================

PWP-GT

=============================================================================

. *In order to define time to each event from the time of the previous one, 
. *a gap time variable has to be generated, and initial times for all time spans are set to zero.
. use "${pathdata2}five_st_msprep_apr22.dta", clear       

. matrix mat_five_states = (.,1,.,.,. \ .,.,2,.,. \.,.,.,3,. \.,.,.,.,4 \.,.,.,.,.)

. msset, id(id) states(Readmission_status Readmission2_status Readmission3_status Readmission4_status) ///
>                 times(Readmission_time Readmission2_time Readmission3_time Readmission4_time) transmatrix(mat_five_states)  //* saqué tipo_de_plan_res_1 para que no se empie
> ce a subdividir

. gen time = _stop - _start

. gen time0=0

. *stset gap, fail(status) exit(time .) enter(time0)
. *https://www.stata.com/support/faqs/statistics/multiple-failure-time-data/#cond1
. stset time, fail(_status) exit(time .) enter(time0)

     failure event:  _status != 0 & _status < .
obs. time interval:  (0, time]
 enter on or after:  time time0
 exit on or before:  time .

------------------------------------------------------------------------------
     31,455  total observations
          0  exclusions
------------------------------------------------------------------------------
     31,455  observations remaining, representing
      9,203  failures in single-record/single-failure data
   43733824  total analysis time at risk and under observation
                                                at risk from t =         0
                                     earliest observed entry t =         0
                                          last observed exit t =     4,592

. 
. cap noi drop sch* sca*
variable sch* not found

. stcox  i.tipo_de_plan_res_1 i.TD_1 i.TD_2 i.TD_3 i.TD_4, efron robust nolog strata(_trans) cluster(id) schoenfeld(sch*) scaledsch(sca*)

         failure _d:  _status
   analysis time _t:  time
  enter on or after:  time time0
  exit on or before:  time .

Stratified Cox regr. -- Efron method for ties

No. of subjects      =        2,540             Number of obs    =       2,540
No. of failures      =        2,105
Time at risk         =      1584304
                                                Wald chi2(5)     =       45.68
Log pseudolikelihood =   -11549.852             Prob > chi2      =      0.0000

                                           (Std. Err. adjusted for 635 clusters in id)
--------------------------------------------------------------------------------------
                     |               Robust
                  _t | Haz. Ratio   Std. Err.      z    P>|z|     [95% Conf. Interval]
---------------------+----------------------------------------------------------------
1.tipo_de_plan_res_1 |   1.109356   .0494087     2.33   0.020     1.016623    1.210548
              1.TD_1 |   .8162914   .0391985    -4.23   0.000     .7429685    .8968505
              1.TD_2 |   .8841537   .0476111    -2.29   0.022     .7955932    .9825721
              1.TD_3 |    .813885   .0416321    -4.03   0.000     .7362446    .8997129
              1.TD_4 |   1.068907     .05901     1.21   0.227     .9592867    1.191053
--------------------------------------------------------------------------------------
                                                          Stratified by _trans

. estat phtest, log detail

      Test of proportional-hazards assumption

      Time:  Log(t)
      ----------------------------------------------------------------
                  |       rho            chi2       df       Prob>chi2
      ------------+---------------------------------------------------
      0b.tipo_de~1|            .            .        1             .
      1.tipo_de_~1|     -0.02178         0.96        1         0.3284
      0b.TD_1     |            .            .        1             .
      1.TD_1      |      0.08966        12.56        1         0.0004
      0b.TD_2     |            .            .        1             .
      1.TD_2      |      0.02779         1.42        1         0.2335
      0b.TD_3     |            .            .        1             .
      1.TD_3      |      0.04315         3.20        1         0.0737
      0b.TD_4     |            .            .        1             .
      1.TD_4      |      0.01687         0.56        1         0.4523
      ------------+---------------------------------------------------
      global test |                     20.18        5         0.0012
      ----------------------------------------------------------------

note: robust variance-covariance matrix used.

. * cluster(id)

We checked the proportionality of hazards visually

. graph combine "${pathdata}\stphplot_trans2_12_22.gph" "${pathdata}\stphplot_trans2_22_22.gph" "${pathdata}\stphplot_trans2_32_22.gph" "${pathdata}\stphplot_trans2_42_22.gph"
> , ///
> colfirst ycommon xcommon iscale(*.7) imargin(tiny) graphregion(color(gs16)) ///
> title("Combination of −ln{−ln(survival)} vs. ln(analysis time)" "PWP-GT", size(medium)) cols(2) ///
> note("{it:Note: Ordered by columns, from up to down, left to right;}" "{it:means and 95% CI's; Bandwidth=.8; Natural log of analysis time}", size(tiny)) ///
> l1(Schoenfeld residuals, size(medium)) b1("Log Time since admission (days)", size(medium)) ///
>         name(_tr_ph_ln_srv_t2_22, replace)

.         
. local num 1 2 4

. foreach i of local num {
  2. gr_edit .plotregion1.graph`i'.legend.draw_view.setstyle, style(no)
  3. }

. 
. forvalues i = 1/4 {
  2. gr_edit .plotregion1.graph`i'.yaxis1.style.editstyle majorstyle(tickstyle(textstyle(size(medium)))) editcopy
  3. gr_edit .plotregion1.graph`i'.yaxis1.style.editstyle majorstyle(tickstyle(textgap(zero))) editcopy
  4. gr_edit .plotregion1.graph`i'.yaxis1.style.editstyle majorstyle(tickstyle(textgap(zero))) editcopy
  5. 
. gr_edit .plotregion1.graph`i'.xaxis1.style.editstyle majorstyle(tickstyle(textstyle(size(medium)))) editcopy
  6. gr_edit .plotregion1.graph`i'.xaxis1.style.editstyle majorstyle(tickstyle(textgap(zero))) editcopy
  7. gr_edit .plotregion1.graph`i'.xaxis1.style.editstyle majorstyle(use_labels(no)) editcopy
  8. *gr_edit .plotregion1.graph`i'.xaxis1.style.editstyle majorstyle(alternate(yes)) editcopy
. }

. 
. forvalues i = 1/4 {
  2. gr_edit .plotregion1.graph`i'.yaxis1.title.draw_view.setstyle, style(no)
  3. gr_edit .plotregion1.graph`i'.xaxis1.title.draw_view.setstyle, style(no)
  4. }

. 
. graph export "_tr_ph_ln_srv_t2_22.png", as(png) replace width(2000) height(1000)
(file _tr_ph_ln_srv_t2_22.png written in PNG format)

. graph export "_tr_ph_ln_srv_t2_22.pdf", as(pdf) replace //*width(2000) height(2000) orientation(landscape)
(file _tr_ph_ln_srv_t2_22.pdf written in PDF format)

. 

Explored schoenfeld residuals:

. drop sch* sca*

. stcox  i.tipo_de_plan_res_1 i.TD_1 i.TD_2 i.TD_3 i.TD_4, efron robust nolog strata(_trans) cluster(id) schoenfeld(sch*) scaledsch(sca*)

         failure _d:  _status
   analysis time _t:  time
  enter on or after:  time time0
  exit on or before:  time .

Stratified Cox regr. -- Efron method for ties

No. of subjects      =        2,540             Number of obs    =       2,540
No. of failures      =        2,105
Time at risk         =      1584304
                                                Wald chi2(5)     =       45.68
Log pseudolikelihood =   -11549.852             Prob > chi2      =      0.0000

                                           (Std. Err. adjusted for 635 clusters in id)
--------------------------------------------------------------------------------------
                     |               Robust
                  _t | Haz. Ratio   Std. Err.      z    P>|z|     [95% Conf. Interval]
---------------------+----------------------------------------------------------------
1.tipo_de_plan_res_1 |   1.109356   .0494087     2.33   0.020     1.016623    1.210548
              1.TD_1 |   .8162914   .0391985    -4.23   0.000     .7429685    .8968505
              1.TD_2 |   .8841537   .0476111    -2.29   0.022     .7955932    .9825721
              1.TD_3 |    .813885   .0416321    -4.03   0.000     .7362446    .8997129
              1.TD_4 |   1.068907     .05901     1.21   0.227     .9592867    1.191053
--------------------------------------------------------------------------------------
                                                          Stratified by _trans

. 
. estat phtest, log plot(1.tipo_de_plan_res_1) yline(0) msym(oh) ///
>          xtitle("Time (days)", size(small)) ///
>         xlabel(0(1460)5000, labsize(vsmall)) ///        
>         ylabel(-4(1)4, labsize(vsmall)) ///     
>         ytitle("Schoenfeld residuals", size(small)) scheme(sj) graphregion(color(white)) ///
>         note("{it:Note. Means and 95% CI's; Bandwidth=.8; Natural log of analysis time used.}",size(vsmall)) ///
>         title("Plot of scaled Schoenfeld residuals versus" "time produced for the covariate Treatment Completion", size(medium)) ///
>         subtitle("{it: specified by Running mean smoother}",size(small)) ///
>         name(phtest_log_TD_1_2_22, replace)  ///
>         saving(phtest_log_TD_1_2_22gph, replace)
(file phtest_log_TD_1_2_22gph.gph saved)

. ***The stphtest command with the plot option will provide the graphs with a lowess curve.  
. ***The usual graphing options can be used to include a horizontal reference line at y=0. 

. qui estread "${pathdata2}parmodels_m3_apr22.sters"

. stcox  i.tipo_de_plan_res_1 i.TD_1 i.TD_2 i.TD_3 i.TD_4, efron robust nolog strata(_trans) cluster(id) tvc(TD_1 _start)

         failure _d:  _status
   analysis time _t:  time
  enter on or after:  time time0
  exit on or before:  time .


Stratified Cox regr. -- Efron method for ties

No. of subjects      =        2,540             Number of obs    =       2,540
No. of failures      =        2,105
Time at risk         =      1584304
                                                Wald chi2(7)     =       71.82
Log pseudolikelihood =   -11531.831             Prob > chi2      =      0.0000

                                           (Std. Err. adjusted for 635 clusters in id)
--------------------------------------------------------------------------------------
                     |               Robust
                  _t | Haz. Ratio   Std. Err.      z    P>|z|     [95% Conf. Interval]
---------------------+----------------------------------------------------------------
main                 |
1.tipo_de_plan_res_1 |   1.121634   .0522404     2.46   0.014     1.023779    1.228842
              1.TD_1 |   .5517483    .051845    -6.33   0.000      .458942    .6633216
              1.TD_2 |   .8831126    .050018    -2.19   0.028     .7903245    .9867944
              1.TD_3 |   .8119301   .0436107    -3.88   0.000        .7308    .9020669
              1.TD_4 |   1.087725   .0628938     1.45   0.146     .9711842    1.218251
---------------------+----------------------------------------------------------------
tvc                  |
                TD_1 |   1.000627   .0001209     5.19   0.000      1.00039    1.000864
              _start |          1   7.18e-08     4.05   0.000            1           1
--------------------------------------------------------------------------------------
                                                          Stratified by _trans
Note: Variables in tvc equation interacted with _t.

. estimates store m3_pwpgt

. estwrite _all using "${pathdata2}parmodels_m3_apr22.sters", append
(appending m3_pwptt)
(appending m3_pwpgt)
(file C:/Users/CISS Fondecyt/Mi unidad/Alvacast/SISTRAT 2019 (github)/_mult_state_ags/parmodels_m3_apr22.sters saved)

Saved at= 17:13:26 10 May 2022