Using STATA for self-controlled case series studies
Our 2006 Statistics in Medicine tutorial paper explains how to carry out a case series analysis using STATA. The files corresponding to the examples in this paper are given below.
Correction to section 4.3 of the tutorial paper: It is no longer necessary to download the file aglm.ado as the standard STATA command xtpoisson can be used to fit conditional Poisson regression models with absorbing factors. The following command is given to fit a standard case series model:
xi: xtpoisson nevents i.exgr i.agegr, fe i(indiv) offset(loginterval)
All the example do-files below now use xtpoisson.
MMR and meningitis in Oxford example
To run the MMR and meningitis in Oxford example detailed in the tutorial paper save these two files in your STATA working directory:
oxford.dta, the data in a STATA data file.
oxford.do, the commands in a STATA do file.
Then 'do' the do file (type do oxford in the command window, or open in the STATA do file editor and press Ctrl+D, or click on Do current file). Details of what the commands in the file are doing are given in the file itself as well as in the tutorial paper.
ITP and MMR example
ITP and MMR data itp.dta
Do file for multiple risk periods (also multiple events) itp.do
Do file for unique and non-independent events itp_non_ind.do
Intussusception and oral polio vaccine examples
Intussuseption and OPV data intuss.dta
Do file for analysis 1, event dependent exposure intuss_analysis1.do
Analysis 2, intuss_analysis2.do
Analysis 3, intuss_analysis3.do
Do file including covariates and Interactions intuss_interact.do
Analysis 4, repeat exposures intuss_analysis4.do
Analysis 5, intuss_analysis5.do
Analysis 6, Multiple exposures intuss_analysis6.do
Correction to section 4.3 of the tutorial paper: It is no longer necessary to download the file aglm.ado as the standard STATA command xtpoisson can be used to fit conditional Poisson regression models with absorbing factors. The following command is given to fit a standard case series model:
xi: xtpoisson nevents i.exgr i.agegr, fe i(indiv) offset(loginterval)
All the example do-files below now use xtpoisson.
MMR and meningitis in Oxford example
To run the MMR and meningitis in Oxford example detailed in the tutorial paper save these two files in your STATA working directory:
oxford.dta, the data in a STATA data file.
oxford.do, the commands in a STATA do file.
Then 'do' the do file (type do oxford in the command window, or open in the STATA do file editor and press Ctrl+D, or click on Do current file). Details of what the commands in the file are doing are given in the file itself as well as in the tutorial paper.
ITP and MMR example
ITP and MMR data itp.dta
Do file for multiple risk periods (also multiple events) itp.do
Do file for unique and non-independent events itp_non_ind.do
Intussusception and oral polio vaccine examples
Intussuseption and OPV data intuss.dta
Do file for analysis 1, event dependent exposure intuss_analysis1.do
Analysis 2, intuss_analysis2.do
Analysis 3, intuss_analysis3.do
Do file including covariates and Interactions intuss_interact.do
Analysis 4, repeat exposures intuss_analysis4.do
Analysis 5, intuss_analysis5.do
Analysis 6, Multiple exposures intuss_analysis6.do
Semi-parametric model
Farrington CP and Whitaker HJ. Semi-parametric analysis of case series data. JRSS C, 2006, 55(5): 553-594.
STATA do files to run a semi-parametric self-controlled case series analysis are available for
- the MMR and meningitis in Oxford data oxford_sp.do
- the ITP and MMR data itp_sp.do.
- the OPV and intussusception data intuss_sp.do similar to Analysis 1 in the tutorial; the analysis for this data is more computationally intensive.
These do files require the day before the start of the observation period to be named sta, the end of the observation period end, the individual identifier indiv and the day the adverse event occurred eventday. Generate the exposure group cut points, naming them excp1, excp2, excp3 etc... and put the number of exposure group cut points - 1 (usually this is the number of exposure groups) into a local macro named nexgr. Exposure group factors are generated as in the parametric models as a list of increasing ordinals with a zero on the end, so if the exposure groups do not necessarily occur one straight after another it will be necessary to correct them using a recode function as described in section 6.6 (repeat exposures) in the tutorial paper.
Farrington CP and Whitaker HJ. Semi-parametric analysis of case series data. JRSS C, 2006, 55(5): 553-594.
STATA do files to run a semi-parametric self-controlled case series analysis are available for
- the MMR and meningitis in Oxford data oxford_sp.do
- the ITP and MMR data itp_sp.do.
- the OPV and intussusception data intuss_sp.do similar to Analysis 1 in the tutorial; the analysis for this data is more computationally intensive.
These do files require the day before the start of the observation period to be named sta, the end of the observation period end, the individual identifier indiv and the day the adverse event occurred eventday. Generate the exposure group cut points, naming them excp1, excp2, excp3 etc... and put the number of exposure group cut points - 1 (usually this is the number of exposure groups) into a local macro named nexgr. Exposure group factors are generated as in the parametric models as a list of increasing ordinals with a zero on the end, so if the exposure groups do not necessarily occur one straight after another it will be necessary to correct them using a recode function as described in section 6.6 (repeat exposures) in the tutorial paper.
Analysis for censored, perturbed or curtatiled post-event exposures
The do files below were used to fit analysis 4 of the validation study in the paper
Farrington CP, Whitaker HJ and Hocine MN. Case series analysis for censored, perturbed or curtailed post-event exposures. Biostatistics, 2009, 10(1): 3-16
The files use the intussusception and OPV data from the tutorial paper.
intuss_censored.do
intuss_cens_pseudo.do this second do file contains the pseudo-likelihood. This can be bootstrapped to get confidence intervals, the bootstrap command is shown at the end of intuss_censored.do, though we have preceeded it with a * so that it will not run, as it is very slow.
The do files below were used to fit analysis 4 of the validation study in the paper
Farrington CP, Whitaker HJ and Hocine MN. Case series analysis for censored, perturbed or curtailed post-event exposures. Biostatistics, 2009, 10(1): 3-16
The files use the intussusception and OPV data from the tutorial paper.
intuss_censored.do
intuss_cens_pseudo.do this second do file contains the pseudo-likelihood. This can be bootstrapped to get confidence intervals, the bootstrap command is shown at the end of intuss_censored.do, though we have preceeded it with a * so that it will not run, as it is very slow.