liminfo

Stata Reference

Free reference guide: Stata Reference

25 results

About Stata Reference

The Stata Reference is a comprehensive cheat sheet covering essential Stata commands for statistical analysis and econometrics. The data management section documents file import (DTA, CSV, Excel), describe/codebook for variable inspection, generate/replace for variable creation, keep/drop/rename for data subsetting, merge/append for combining datasets, and reshape for wide-to-long transformations.

Regression analysis entries cover OLS with robust and cluster standard errors, VIF diagnostics and heteroscedasticity tests, logistic regression with classification tables and ROC curves, multinomial/ordinal logit, margins for marginal effects and predicted probabilities, predict/estat post-estimation diagnostics, ivregress for instrumental variable estimation (2SLS), and structural equation modeling (SEM) with path analysis and confirmatory factor analysis.

Panel and time series commands include xtreg for fixed and random effects with Hausman test, xtlogit/xtprobit for binary panel models, areg/reghdfe for high-dimensional fixed effects, and difference-in-differences estimation. Survival analysis covers stset, stcox (Cox proportional hazards), streg (parametric models), Kaplan-Meier curves, and log-rank tests. Also included are complex survey analysis (svy:), graph commands, and descriptive statistics with tabstat.

Key Features

  • Data management: import DTA/CSV/Excel, describe, generate/replace, keep/drop, merge/append, reshape
  • Descriptive statistics: summarize with detail, tabulate cross-tabulation, ttest, tabstat, and SEM
  • Regression analysis: OLS with robust/cluster SE, logistic regression, multinomial/ordinal logit, ivregress 2SLS
  • Post-estimation: margins for marginal effects, predict, estat VIF/hettest/ovtest/gof, Wald tests
  • Panel data: xtreg FE/RE with Hausman test, xtlogit/xtprobit, areg/reghdfe, diff-in-diff
  • Survival analysis: stset, stcox Cox PH, streg parametric, Kaplan-Meier, log-rank, stcurve
  • Complex survey analysis (svy:) with weights, stratification, clustering, and graph export
  • Searchable by category with dark mode support across desktop, tablet, and mobile devices

Frequently Asked Questions

How do I import and manage data in Stata?

Use "use file.dta, clear" for Stata files, "import delimited" for CSV, or "import excel" with firstrow option. Inspect data with describe and codebook, create variables with generate/egen, filter with keep/drop if, merge datasets with "merge 1:1 id using file2.dta", and reshape between wide and long formats.

How do I run OLS regression with robust standard errors in Stata?

Use "regress y x1 x2, vce(robust)" for heteroscedasticity-robust standard errors or "vce(cluster id)" for cluster-robust SE. Check diagnostics with "estat vif" for multicollinearity, "estat hettest" for heteroscedasticity, and "estat ovtest" for model specification. Use "predict yhat" for fitted values and "predict resid, residuals" for residuals.

What is the difference between logit and logistic in Stata?

Both fit binary logistic regression, but "logit" reports coefficients as log-odds while "logistic" reports odds ratios directly. After fitting, use "estat classification" for the classification table, "lroc" for the ROC curve, and "lstat" for sensitivity/specificity analysis. Use "margins, dydx()" for average marginal effects.

How do I perform fixed effects and random effects panel regression?

First declare panel structure with "xtset id year". Use "xtreg y x, fe" for fixed effects and "xtreg y x, re" for random effects. Run "hausman fe re" to test which is preferred. Use "xttest0" for the Breusch-Pagan LM test. For binary outcomes, use xtlogit/xtprobit with fe or re options.

How does the margins command work in Stata?

After fitting a model, "margins sex" gives predicted probabilities by group, "margins, dydx(age)" computes the average marginal effect of age, and "margins sex, at(age=(30(10)70))" shows predictions at specific age values by sex. Use "marginsplot" to visualize the results as publication-ready graphs.

How do I run survival analysis in Stata?

Declare survival data with "stset time, failure(event==1)". Use "sts graph" for Kaplan-Meier curves, "sts test group" for log-rank tests, "stcox age sex i.treatment" for Cox proportional hazards, "estat phtest" to check the PH assumption, and "streg age sex, dist(weibull)" for parametric models.

How do I implement difference-in-differences in Stata?

Create treatment indicators: "gen post = (year >= 2020)" and "gen treat_post = treatment * post". Run "regress outcome treatment post treat_post, vce(cluster id)" where the treat_post coefficient is the DID estimate. For staggered treatments, consider external packages like did_multiplegt or csdid.

Is this Stata reference free to use?

Yes, this Stata Reference is completely free with no account required. All content runs in your browser with zero server processing. It is part of liminfo.com's collection of free statistics and data analysis reference tools.