Home | R | Python | Stata
Coding Smartly

First steps

Stata Interface (User interface; Getting help)
Being Reproducible (Working directory; Log file; Do-file)
Syntax, or How to Speak Stata (Syntax; Operators)
Reading and Saving Files of Various Types (.dta, .xls, .xlsx, .txt, .csv; Comma/tab delimited files)

Exploring data

Describing Your Data (describe; codebook; list; count)
Summarizing Your Data (summarize; tabulate; tabstat; table)
Correlation (correlate; pwcorr)

Transforming variables

Creating and Recoding Variables (generate; recode; replace; egen; autocode)
Variable Names, Labels, and Values (rename; label variable; label define; label values; label list; label drop)
Converting Numeric/String Variables (encode/decode; real()/string(); destring/tostring)
Creating Dummy Variables (Dummy variables/indicator variables; Factor variables)

Transforming dataset

Subsetting (keep; drop)
Arranging Your Data (sort; gsort; order)
Binding Datasets (append; merge; joinby)
Reshaping Your Data (reshape; collapse)

Useful tricks in hierarchical data

(Creating group identifier; First/last cases within a group; Checking if values are consistent within a group; Checking if t test pairs exist within a group; Lags and leads)
Spreading Rows in Hierarchical Data (fill; expand; by prefix with sum(), max(), min(), mean() etc.)


Matching and searching: regexm(); regexr(); regexs(); strpos(); strrpos();
Parsing and extracting: split; substr(); subinstr(); egen, ends(); strtrim(); stritrim();strltrim();strrtrim();
Conversion: string(); real();
Concatenation: egen, concat(); + operator

Dates and times

Dates and Times
(Data types and storage types; Display format; Conversion; Extraction; Concatenation; Calculation)

Automating your work

Automating Your Work (Macros; The many uses of macros; Loops: foreach/forvalues/while)
Stored Results
(r-class and e-class commands; Types of results; Storing results in a matrix; levelsof; System variables; tempvar; word)
Useful Commands in Programs
(quiet; preserve/restore)

Recommended Resources

Resources for Self-Paced Learning (Introduction to Stata; Practical guides; Statistical analysis examples)