Basic STATA Commands

Items in bold are Stata commands.
Items in italics represent variable names or numbers.

For example, the following items in italics represent:
nvar (Numerical variable)
cvar (Categorical variable)
a b c d (Observed cases in exposed and unexposed groups).

Descriptive statistics:

To compute a one-way frequency table
tab nvar or cvar
To compute a two-way frequency table
tab cvar1 cvar2
To compute a two-way frequency table with column percentage
tab cvar1 cvar2, col
To compute a two-way frequency table with row percentage
tab cvar1 cvar2, row
To compute summary statistics (mean, SD, range)
sum nvar
To compute detailed summary statistics (mean, median, SD, range, IQR)
sum nvar, d
To compute detailed summary statistics by a category
tabstat nvar, by(cvar) stats(n mean med sd p25 p75 min max)
To produce a Box and whisker plot (Stata 8)
graph box nvar graph box nvar, by(cvar)
To compute Shapiro-Wilk test
swilk nvar
swilk nvar if cvar == 1
To compute geometric mean
means nvar
means nvar if cvar == 1

Confidence interval and hypothesis testing:

Numerical data:
To compute 95% confident interval for population mean (immediate command)
cii n mean sd
To compute one sample t-test (immediate command)
ttesti n mean sd mean1
(mean1 represents the hypothesized mean value)
To compute two sample t-test for independent samples (immediate command)
ttesti n1 mean1 sd1 n2 mean2 sd2
To compute two sample t-test for independent samples
ttest nvar, by(cvar)
To compute paired t-test
ttest before = after
To compute tests on the equality of variances (immediate command)
sdtesti n1 . sd1 n2 . sd2
To compute tests on the equality of variances
sdtest nvar, by(cvar)
To compute two sample Wilcoxon rank-sum test for independent samples
ranksum nvar, by(cvar)
To compute Wilcoxon signed rank test for paired observations
signrank before = after
One-way Analysis of Variance (ANOVA)
oneway, bonferroni tab
To compute Kruskal-Wallis test
sort cvar
kwallis nvar, by(cvar)
Categorical data:
To compute a one-way frequency table
tab cvar
To compute 95% confident interval for a Binomial proportion (immediate command)
cii n cases
To compute a Chi-squared test in a two-way table
tab cvar1 cvar2, ch
To compute a expected frequency in a two-way table
tab cvar1 cvar2, exp
To compute a Fisher exact test in a two-way table
tab cvar1 cvar2, exact
To compute an OR from a two-way table (immediate command)
tab a b c d
where a=Case(+exp) b= Case(-exp) c= Control(+exp) d= Control(-exp)
To compute an RR from a two-way table (immediate command)
tab a b c d
where a=Case(+exp) b= Case(-exp) c= Control(+exp) d= Control(-exp)