Doctors Revision

STATA for Biostatistics and Epidemiological Data Analysis

STATA for Biostatistics and Epidemiological Data Analysis

STATA is statistical software widely used for data management, biostatistics and epidemiology. Its command-based workflow supports transparent, repeatable analysis through do-files.

Learning objectives

  • Understand the STATA interface and dataset structure.
  • Import, label, clean and save health data.
  • Produce descriptive statistics, tables and graphs.
  • Perform common epidemiological tests and preserve reproducibility.

Main interface

  • Command window: enter commands.
  • Results window: view output.
  • Variables window: inspect variable names and labels.
  • Review window: view recent commands.
  • Do-file Editor: write and rerun a documented analysis script.

Starting a project

clear all
set more off
cd "project-folder"
import excel "healthdata.xlsx", firstrow clear
describe
codebook
save "healthdata_clean.dta", replace

Use de-identified data and approved secure folders. Never overwrite the only raw dataset; keep raw, cleaned and analysis files separate.

Data inspection

describe, codebook, summarize, tabulate, list and misstable summarize.

Data management

generate, replace, recode, rename, label, sort, merge and append.

Descriptive analysis

PurposeExample command
Summarise agesummarize age, detail
Frequency tabletabulate sex
Cross-tabulation with chi-squaretabulate exposure outcome, chi2 row
Compare two meansttest bp, by(treatment)
Correlationpwcorr age bp, sig
Linear regressionregress bp age i.sex
Logistic regressionlogistic outcome exposure age i.sex

Epidemiological analysis

Commands such as cc and cs can analyse case-control and cohort/tabular data. Always define exposure, outcome, reference categories and study design before choosing a command. Report effect estimates with confidence intervals, not p-values alone.

Example workflow

use "healthdata_clean.dta", clear
assert inrange(age,0,120) if !missing(age)
tabulate outcome exposure, row chi2
logistic outcome exposure age i.sex
estimates store model1
log close

The assert command checks a rule; modelling then estimates an adjusted association. Examine model assumptions, influential observations, confounding and interaction before interpretation.

Graphs

  • histogram age, normal examines a distribution.
  • graph bar (percent), over(outcome) displays proportions.
  • scatter bp age shows a numerical relationship.
  • twoway line cases week shows a time trend.

Reproducible practice

  1. Write commands in a do-file with comments.
  2. Open a log file to preserve output.
  3. Use relative project paths where possible.
  4. Record software version and installed packages.
  5. Set a random-number seed for simulations or sampling.
  6. Export final tables and graphs without manually changing results.
Exam tip: know the logic of the workflow—import, describe, clean, label, analyse, check assumptions, interpret, save and document.

Review questions

  1. Why is a do-file preferable to entering commands only interactively?
  2. Which command creates a two-way table with a chi-square test?
  3. Differentiate merge from append.

Return to the Clinical Medicine Year 2 curriculum

References

  • StataCorp. Stata Base Reference Manual.
  • StataCorp. Epidemiological Tables Reference Manual.

Educational content only; analysis of real patient data must follow ethical, privacy and institutional requirements.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top