User guide

Learn commands by task

Choose what you want to do with your data. Each command guide explains the syntax and options, then provides a complete example you can open and run in the browser.

Start with an example

  1. Choose a task below and read the command's purpose, syntax, and options.
  2. Go to its Example section and select Open example in browser. A new tab opens with the complete script and sample data.
  3. Click Run in the app. Read the results beneath the commands and compare them with the guide's explanation.

If you are new to command-based analysis, begin with importing a CSV, then summarize its numeric variables. Change one command at a time and run the example again to see its effect.

Open and import data

import delimited
Read a CSV or other delimited text file, then check variable types and observation counts.
Open a .dta file
Load a Stata-format dataset and inspect its variables and values.
Open a do-file
Work with a saved sequence of commands and run it in order.

Create and prepare variables

generate
Create calculated variables, indicators, and running totals from expressions.
replace
Change selected values in an existing variable, including missing values.
recode
Map numeric values or ranges into new categories.
egen
Calculate row means and totals, repeat group summaries, or identify combinations of values.
duplicates
Report, tag, or remove repeated observations using the variables that define a record.
reshape
Move repeated measurements between wide columns and long rows.
merge
Join datasets by an identifier and check matched and unmatched observations.

Summarize data and compare groups

summarize
Inspect counts, means, standard deviations, ranges, and missing-value differences.
tabstat
Choose the statistics to show in a summary table for several variables or groups.
tabulate
Count categories in one-way or two-way frequency tables.
collapse
Replace the current observations with summary statistics for each group.
ttest
Compare a mean with a reference value, two independent means, or paired measurements.
ranksum
Compare two independent groups using the ranks of their observations.

Calculate correlations and fit models

correlate
Calculate a Pearson correlation matrix using a common sample of observations.
pwcorr
Calculate correlations using the observations available for each pair of variables.
regress
Fit a linear regression and interpret coefficients and their standard errors.
logit
Model a binary outcome and read its log-odds coefficients.
predict
Create fitted values, residuals, and standard errors after fitting a model.

Build a longer workflow

Use a do-file to keep the steps of an analysis together. The paper replication directory provides longer scripts alongside their paper and data citations.

For commands beyond these guides, consult the supported-command list. For classroom use, see working from a Chromebook.