Stata Commands

Lesson 1

sysdirDetails State program directory
pwdcurrent working directory
cdchange current directoryLesson 1File System
mkdircreate a new file in working folderLesson 1File System
dir [*.xxx]list files in working folderLesson 1File System
erase yyy.xxxdeletes "yyy.xxx"Lesson 1File System
copy old.xxx new.xxxCopies fileLesson 1File System
type yyy.xxxdisplays contents of yyy.xxxLesson 1File System
use yyy.xxx[, clear]opens datasetLesson 1File System
save yyy.xxx[, replace]saves fileLesson 1File System
describeprovides details of datasetLesson 1Data
listlists dataLesson 1Data
summarize [var]basic summary statisticsLesson 1Data
sort varsorts by varLesson 1Data
drop vardiscards varLesson 1Data
generate var = expgenerates new variable according to expLesson 1Data
note: "text" [TS]add note to dataset [timestamp]Lesson 1Data
notesshow notesLesson 1Data
note drop _dta in rangeerase notesLesson 1Data
log using yyy[,append|replace]start [append/replace] a logLesson 1Data
command varlist if exp in range
Getting online helpsearch, findit, help
Operating system interfacepwd, cd, sysdir, mkdir,rmrdir,dir,erase,copy, type
Using and saving data from diskuse, save,append,merge,compress
Inputting data into Statainput,edit,infile,infix,insheet
The internet and updating Stataupdate,net,ado,news
Basic data reporting descirbe,codebook,list,browse,count,inspect,summarize, table,tabulate
Data manipulation generate,replace,egen,rename,drop,keep,sort,encode,decode,order,by,reshape,collapse
Formattingformat,label
Keeping Track of your worklog,notes
Convenience

Lesson 2

compressredefines variables to minimize memory takenLesson 2.1.1
set mem xMchanges memory allocated to stata where x is a numberLesson 2.1.1
describe [varlist] gives type, format, labelsLesson 2.1.1
codebook [varlist]type, # unique, # missing, warningsLesson 2.1.1
label define varlabel x "description"defines the entries of varlabel (for example, if varlabel were gender:
label define gender 0 "female" 1 "male"
Lesson 2.1.2
label values var [varlabel]associates the descriptions with the variable or erases varlabels if
varlabel excluded.
Lesson 2.1.2
[, nolabel]option to ignore special labels (used with tabulate, list)Lesson 2.1.2
??set type %#.#xformats variablesLesson 2.1.3
format varlist %#.#xformats variablesLesson 2.1.3
label data [datalabel]labels entire dataset [or clears label]Lesson 2.1.4
browsealternative to listLesson 2.3
count [if exp] [in range]counts observationsLesson 2.3
inspectLesson 2.3
tableLesson 2.3
tabulateLesson 2.3
by varlist: cmd performs the command separately for each group within varlistLesson 2.3
generate [type] newvar = exp creates a new variable according to expression where type is the data typeLesson 2.4Data Manipulation
replace oldvar = exp [if exp]
[in range]
just like generate but replaces old dataLesson 2.4Data Manipulation
egenLesson 2.4Data Manipulation
word(s, n) Retrieves a word from a string.  s = string to parse, n = which word to retrieve. word("Happy Birthday",2) = "Birthday"Lesson 2.4Data Manipulation
group(var)for a string variable assigns each unique entry an indexLesson 2.5
egen varlike generate, but with special powersLesson 2.5
encode oldvar, gen(newvar)Lesson 2.5
sum(var)cumululative sum of variable dataLesson 2.5
_nnumber of observation (ie, 3rd observation in a group)Lesson 2.5
_Ntotal number of observations in a groupLesson 2.5

Lessons 3-4

infile varlist using filenameinputs variables in varlist from filenameLesson 3.1
infile using filenameinputs variables according to dictionary named filenameLesson 3.1
outsheet [varlist] using filename if exp in rangesaves variables into format (tab-delimited by default)Lesson 3.1
insheet using filenameLesson 3.1
duplicates [op] varlistwill find (and more) duplicates in a variableLesson 4.2.1
reshapeconverts table between wide and long forms Lesson 4.4

Reshape

reshape long|wide stubnames[@], i(varlist) [options]
SSNageinc03inc04inc05
34675246854565861
34857642551737677
34651248738404141
®
reshape long inc, i(SSN) j(income)

reshape wide income, i(SSN) j(inc)
¬
SSNageyearincome
346752468540356
346752468540458
346752468540561
348576425510373
348576425510476
348576425510577
346512487380340
346512487380441
346512487380541