Summary of Basic STATA Commands and Syntax
Summary of Basic STATA Commands and Syntax
Syntax
use filename [, clear nolabel]
insheet [varlist] using filename [,
options]
Common options include [tab, comma,
clear]
edit [varlist] [if] [in] [, nolabel]
clear
save [filename] [, save_options]
Common options include [replace]
Commands for checking and verifying data
describe
datafile name and path, n, d [varlist] [, options]
no. of variables, variable
common option: fullnames =>does not
names, types and labels,
abbreviate variable names
how the data are sorted.
(Note type includes
string, and various
numeric types requiring
different amounts of
memory)
summarize
mean, sd, min, max, n
su [varlist] [if] [, options]
su,detail
percentiles, medians,
su [varlist] [if] ,detail
kurtosis, skewness,
highest and lowest values
ci
standard errors (SE) and
ci [varlist] [if] [, options]
confidence intervals
common option is: level(#); default is
level(95)
browse
allows you to browse (no
edit [varlist] [if] [,nolabel]
edit
changes allowed) or edit
Note: nolabel displays codes instead of
(changes allowed) data as labels.
if it were in spreadsheet
form
list
lists values of variables
list [varlist]
list in 1/n (will list the first n
observations).
sort
sort the data by the
sort varlist
gsort
variable(s) indicated in
gsort [+|-] varname [[+|-] varname ...]
ascending order; gsort
allows sorting also in
descending order
14 January 2014
STATA
command
by
bysort
tab
Function
Syntax
tab, sum
table
Table of summary
statistics
if exp
log
set mem
14 January 2014
STATA
command
set more
global
Function
Syntax
cd
14 January 2014
STATA
command
egen
Function
Syntax
Extensions to generate
variable, allows creation of
max, min, sd, mean, total,
count of non-missing,
deviation from mean, etc.
tab, gen
mvdecode
mvencode
rename
label
Renames the
Creates label
Creates label
Creates label
destring,rep
lace
compress
variable
for datasets
for variables
for values
14 January 2014
STATA
command
foreach
Function
Syntax
collapse
Makes a dataset of
summary statistics
reshape
foreach `x in varlist {
commands referring to `x' in
varlist
}
merge 1:1 varlist using filename.dta
(matches individual observations)
merge 1:m varlist using filename.dta
(matches 1 observation in using file to
multiple observations in merging file).
merge m:1 varlist using filename.dta
(matches multiple observations in using
file to single observation in merging
file).