Statistics with Stata: an interactive guide
The core ideas of the course as simulations you can change, each with the Stata command that does it
Companion to Introduction to Statistics in Stata (Quantitative Statistics, Advanced Quantitative Statistics and the Getting Started with Stata do-files).
Statistics is about learning from a sample about a population we cannot see in full. The simulations below create a population whose true values we know, draw samples from it, and show how the statistics behave. That is how you build intuition for standard errors, confidence intervals, p-values and model coefficients. Every simulation runs in your browser; press a button again for a fresh draw.
1Sampling distributions and the central limit theorem
A sample mean varies from sample to sample. Its spread across repeated samples is the standard error, σ/√n. The central limit theorem says that sample means are close to normally distributed once n is moderately large, even when the population is not normal.
2Confidence intervals
A 95% confidence interval is built by a method that captures the true mean in 95% of samples. Any single interval either contains it or does not; the 95% describes the method, not one interval.
3Hypothesis tests, errors and power
A significance test asks how surprising the data would be if there were no difference. Two errors are possible: a Type I error (finding a difference that is not there, with probability α) and a Type II error (missing one that is). Power is the chance of detecting a real difference.
Statistical significance is not practical importance. With a very large sample a tiny, unimportant difference can have a minute p-value; report the size of the difference and its confidence interval as well.
4Correlation and regression
A correlation measures the strength of a linear association. Linear regression estimates how much the outcome changes for each one-unit change in a predictor, and R² is the share of variation in the outcome that the model accounts for.
5Confounding
A confounder Z affects both the predictor X and the outcome Y. Leave it out and the coefficient on X picks up part of Z’s effect. Including Z in the model recovers the true effect, if Z is measured well.
The course also covers suppression, where leaving out a variable hides an effect because two paths of opposite sign cancel out, and mediation, where Z lies on the path from X to Y. Controlling for a mediator removes part of the effect you want to measure, so the causal ordering matters.
6Interactions
An interaction lets the effect of one variable depend on another. Here the effect of X on Y differs between two groups.
7Logistic regression: odds ratios and marginal effects
For a yes/no outcome, logistic regression models the log-odds. Its coefficient is often reported as an odds ratio. An odds ratio does not say how much the probability changes: that depends on the baseline probability. The average marginal effect reports the change in probability directly.
8Check yourself
9Course files
- Quantitative Statistics (PDF): sampling, distributions, probability, estimation, tests, contingency tables, correlation, t-tests, ANOVA, regression diagnostics
- Advanced Quantitative Statistics (PDF): confounding, mediation and moderation; logistic, ordinal and multinomial models; fixed and random effects; multilevel models; instrumental variables; regression discontinuity; count models
- Do-files: #1 Stata basics, #2 statistics and regression, #3 interactions, logistic and other models; example dataset