**********************************************************************************************
*Stata code for replication results reported in Cook JA. An introduction to clinical trials. OUP 1st Edition, 2023.
*21Aug2023
*LEAP Trial analysis code used to generated results 
*See key publication Du Toit et al, LEAP Trial, 2015 (doi: 10.1056/NEJMoa1414850)
*Dataset available from https://www.itntrialshare.org/tsstatic/Terms%20Of%20Use.html 

*Chapter 9 Table 9.2 p214 analysis of allergy (positive skin prick test) result

**********************************************************************************************
*Set-up log file - update with address for storing log file
*log using "XXXX.smcl", replace

**********************************************************************************************
*Import dataset - update address to where dataset is stored (available from website listed above)
*import excel "LEAP trial datatset PO_ADPOUT1_nejm_2021-10-16_03-11-42.xlsx", sheet("data") firstrow

**********************************************************************************************
*Check participant number overall, by stratum, and by randomised group, and also number included in ITT analysis of the primary outcome
tab ParticipantID

*Fig 1 - 640 were randomised matches number of rows

*Included in ITT anlaysis 
*Note matches Fig 1 of Du Toit et al (2015) has 263+1+266+51+6+41=628 in ITT
tab IntenttotreatITTSample

*Note matches Fig 1 of Du Toit et al (2015) fig 1 for randomised numbers overall
tab TreatmentGroupChar
tab TreatmentGroupChar, nolabel

*Matches stratum Fig 1 numbers - 542 and 98
tab Stratumchar

**********************************************************************************************
*Generate indicator variables to use in analysis

*Generate indicator variable for treatment group
gen TreatGroup_indicator=1 if TreatmentGroupChar=="Peanut Avoidance"
replace TreatGroup_indicator=0 if TreatmentGroupChar=="Peanut Consumption"
tab  TreatGroup_indicator TreatmentGroupChar

*Generate indicator variable for baseline stratum group (SPT-negative/positive) 
gen Stratumchar_indicator=1 if Stratumchar=="SPT-positive Stratum"
replace Stratumchar_indicator=0 if Stratumchar=="SPT-negative Stratum"
tab  Stratumchar_indicator Stratumchar

***************
*Check number randomised by baseline stratum 
*Randomised by baseline stratum group (SPT-negative/positive) - matches Figure 1
tab Stratumchar_indicator TreatGroup_indicator

***************
*Primary outcome data check

*Note - PO is OverallV60OutcomeOFCIndet not OutcomeofPeanutOFCatV60ch.

tab OutcomeofPeanutOFCatV60ch OverallV60OutcomeOFCIndet
tab OutcomeofPeanutOFCatV60ch TreatmentGroupChar, col

tab  TreatmentGroupChar
tab OverallV60OutcomeOFCIndet, nolabel

gen TOverallV60OutcomeOFCIndet_ind=1 if OverallV60OutcomeOFCIndet=="FAIL OFC"
replace TOverallV60OutcomeOFCIndet_ind=0 if OverallV60OutcomeOFCIndet=="PASS OFC"

*Check indicator
tab  TOverallV60OutcomeOFCIndet_ind OverallV60OutcomeOFCIndet

*Matches values (17.2% and 3.2% for avoidance and consumption groups) for overall combined cohort in Fig 2. 
tab  TOverallV60OutcomeOFCIndet_ind TreatGroup_indicator, col

**********************************************************************************************
*Analysis of primary outcome overall (both baseline SPT strata together)

*Risk difference with 95% confidence interval (CI) [Newcombe's method 10]
rdci TOverallV60OutcomeOFCIndet_ind TreatGroup_indicator

*Risk ratio with 95% CI 
cs TOverallV60OutcomeOFCIndet_ind TreatGroup_indicator

*Odds ratio with 95% CI using logistic regressions
logistic TOverallV60OutcomeOFCIndet_ind TreatGroup_indicator

*Invert direction so that OR/RR<1 and RD <0 indicates less allergy events 
recode TreatGroup_indicator (1 = 0) (0 = 1), gen(Invert_TreatGroup_indicator)

tab  TOverallV60OutcomeOFCIndet_ind Invert_TreatGroup_indicator, col

*Risk difference with 95% confidence interval (CI) [Newcombe's method 10] as per Table 9.2 (Cook, 2023)
rdci TOverallV60OutcomeOFCIndet_ind Invert_TreatGroup_indicator

*Risk ratio with 95% CI result as per Table 9.2 p214 (Cook, 2023)
cs TOverallV60OutcomeOFCIndet_ind Invert_TreatGroup_indicator

*Odds ratio  with 95% CI result as per Table 9.2 p214, (Cook 2023)
logistic TOverallV60OutcomeOFCIndet_ind Invert_TreatGroup_indicator

**********************************************************************************************
*Analyses by stratum (not reported in Chapter 9 (Cook, 2023) but corresponding to analyses reported in paper). 
*Note analyses done separately though a different approach of using the combined dataset but including interaction tests in a regression model could have been used. The analysis of each stratum separately is adopted here which follow the approach in Du Toit et al (2015).


***************
preserve
keep if Stratumchar=="SPT-negative Stratum"

*Risk difference with 95% CI (Newcombe's method 10)
rdci TOverallV60OutcomeOFCIndet_ind Invert_TreatGroup_indicator

*Risk ratio with 95% CI 
cs TOverallV60OutcomeOFCIndet_ind Invert_TreatGroup_indicator

*Odds ratio with 95% CI using logistic regression
logistic TOverallV60OutcomeOFCIndet_ind Invert_TreatGroup_indicator

restore

***************
preserve
keep if Stratumchar=="SPT-positive Stratum"

*risk difference with 95% CI (Newcombe's method 10)
rdci TOverallV60OutcomeOFCIndet_ind Invert_TreatGroup_indicator

*Risk ratio with 95% CI 
cs TOverallV60OutcomeOFCIndet_ind Invert_TreatGroup_indicator

*Odds ratio with 95% CI using logistic regression
logistic TOverallV60OutcomeOFCIndet_ind Invert_TreatGroup_indicator

restore

**********************************************************************************************
*Alternative analysis approaches to overall analysis (not reported in Chapter 9 but some commonly used alternative approaches to handling stratum structure)

***************
*Mantzel-Haenzel (stratified) comparison 
cc  TOverallV60OutcomeOFCIndet_ind TreatGroup_indicator, by(Stratumchar)

***************
*Logistic regression with interaction effect

*Generate treatment interaction effect
gen Stratumtreat_interaction=0
replace Stratumtreat_interaction=1 if ((Stratumchar_indicator==1)&(TreatGroup_indicator==1))
tab Stratumtreat_interaction Stratumchar_indicator

*Logistic regression with treatment-by-stratum subgroup interaction effect
logistic TOverallV60OutcomeOFCIndet_ind TreatGroup_indicator Stratumchar_indicator Stratumtreat_interaction

**********************************************************************************************
*Log close

*Update with location used to store log file
view "XXXX.smcl"
