Stata Tutorial
Learn Stata step by step: 36 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- What Is Stata? Learn what Stata is, who uses it, how it compares with R, Python and SPSS, and how its data model of observations and variables shapes every command you type.
- Editions and Installation Compare Stata BE, SE and MP, understand licenses and system requirements, install and update Stata, and add community packages with ssc install.
- Your First Stata Session Walk through a first Stata session with the built-in auto dataset: load it, describe, list, summarize, make a variable, run a regression, and save a log.
- Command Syntax and Getting Help Learn the general Stata command syntax: prefix, command, varlist, if, in, weights and options after the comma. Use help, search and the manuals to find answers.
Interface and Data
- A Tour of the Stata Interface Learn the Stata windows: Command, Results, History, Variables, Properties, Data Editor and Do-file Editor, plus the menus, preferences and keyboard shortcuts that save time.
- Working Directory and File Paths Control where Stata reads and writes files: cd, pwd, absolute and relative paths, quoting names with spaces, a project folder layout and portable paths with global macros.
- Importing Data into Stata Load data into Stata with use, sysuse, webuse, import delimited and import excel. Learn options for headers, delimiters, encodings, sheets and how to check the result.
- Data Types and Storage in Stata Understand Stata storage types byte, int, long, float, double and strings, display formats, destring, tostring, encode, compress and how Stata stores dates.
- Missing Values and Labels in Stata How Stata stores missing values (., .a to .z), why missing sorts as infinity in comparisons, and how to use variable labels, value labels, notes and label languages.
Data Management
- Generating and Replacing Variables Create and change variables in Stata with generate, replace, egen, recode, cond() and rename. Learn the safe pattern for conditional variables and how to handle missing values.
- Conditions and Logical Operators Select observations in Stata with if and in, combine conditions with & | !, use inlist, inrange and missing(), understand operator precedence and the if/else programming forms.
- Sorting and the by Prefix Sort data with sort and gsort, run commands per group with by and bysort, use _n and _N, find duplicates, create lags and running totals and rank within groups.
- Merging and Appending Datasets Combine datasets in Stata: append stacks rows, merge matches rows by key. Learn 1:1, m:1 and 1:m merges, the _merge variable, keep() and assert() options and common failures.
- Reshaping Data: Wide and Long in Stata Learn the reshape command in Stata: wide versus long layouts, the i and j variables, stub names, reshape long, reshape wide, common errors and when to use collapse and expand.
Descriptive and Graphs
- Summary Statistics with summarize Get descriptive statistics in Stata with summarize, summarize detail, tabstat and mean: percentiles, skewness, weights, group summaries, stored r() results and confidence intervals.
- Tables and Cross-tabulations Build frequency tables and cross-tabulations in Stata with tabulate, tab1, tab2, row and column percentages, chi-square tests, collapse and the modern table command.
- Graph Basics in Stata Draw your first Stata graphs: histogram, scatter plot, line plot, bar graph, box plot and twoway overlays. Learn graph command anatomy, titles, axes, labels, by() and legends.
- Exporting Graphs, Schemes and Styles Save and export Stata graphs to PNG, PDF, SVG and EMF, use graph save and graph use, choose schemes, set colors, fonts and sizes, and build consistent publication-ready figures.
Regression
- Linear Regression with regress Fit and read an ordinary least squares model with Stata's regress command: coefficients, standard errors, R-squared, predict and a runnable Python stand-in.
- Factor Variables, Interactions and margins Use Stata's i. and c. prefixes and ## operator to add dummies, interactions and polynomials to regressions, then interpret them with margins and contrast.
- Regression Diagnostics and Robust Standard Errors Check a Stata regression for heteroskedasticity, multicollinearity, outliers and misspecification with rvfplot, estat hettest, vif and robust or clustered errors.
- Logit, Probit and Marginal Effects Model binary outcomes in Stata with logit and probit, read odds ratios, compute average marginal effects with margins and check classification with estat.
Panel and Time Series
- Panel Data: xtset, xtdescribe and xtsum Declare and explore panel data in Stata with xtset, xtdescribe, xtsum and xttab: long format, balanced versus unbalanced panels, within and between variation.
- Fixed Effects, Random Effects and the Hausman Test Estimate panel models in Stata with xtreg, fe and re, cluster the standard errors, compare them with the Hausman test and see the within transformation work.
- Time Series Basics: tsset, Lags and Plots Prepare time-series data in Stata with tsset and %t date formats, use lag and difference operators, plot with tsline and test for autocorrelation.
- ARIMA Models, Unit Roots and Forecasting Test for unit roots with dfuller, fit AR and ARIMA models with the arima command, read the ACF and PACF, and forecast with predict. Runnable Python stand-ins.
Programming and Do-files
- Do-files, Log Files and a Clean Script Layout Write repeatable Stata do-files: header, version, clear all, set seed, relative paths, log using, comments, line breaks, run and do, plus a script-checker stand-in.
- Macros: Local, Global and Extended Functions Understand Stata macros: local and global definitions, the quote syntax, expressions, extended macro functions, tempvar, scalars and a macro-expander stand-in.
- Loops: foreach, forvalues, while and levelsof Automate repetitive Stata work with foreach, forvalues and while, loop over variables, numbers, files and categories, and use if-else and continue. Python stand-ins.
- Writing Programs, ado-files and Stored Results Write your own Stata commands with program define, syntax, tempvar, rclass and eclass results, ado-files and error handling, plus a Python stand-in.
Reproducible Reporting
- Regression Tables with estimates, estout and esttab Store models with estimates store and build publication-ready regression tables in Stata using esttab, estout, table and collect, exporting to Word, LaTeX or CSV.
- Exporting to Excel, Word and PDF: putexcel, putdocx, graphs Export results from Stata to Excel with export excel and putexcel, build Word and PDF reports with putdocx and putpdf, and save graphs with graph export.
- A Reproducible Research Workflow in Stata Build a reproducible Stata project: folder structure, master do-file, version and seeds, data provenance, checksums, ssc packages, Git and dyndoc.
Projects and Practice
- Project: A Wage Regression from Raw Data to Table Plan and write a complete Stata analysis: clean a survey, explore wages, fit a sequence of log-wage models, check diagnostics and export a table, with a Python rehearsal.
- Project: Policy Evaluation with Difference-in-Differences Evaluate a policy with a panel in Stata: check parallel trends, run a two-way fixed-effects difference-in-differences with xtreg or reghdfe, cluster errors and plot an event study.
- Practice: Stata Regression, Panel and Programming Exercises Ten graded Stata exercises on regression, factor variables, logit, panel data, time series, loops, programs and reporting, with solutions and Python stand-ins.