Useful STATA Commands
Note: Built-in commands are marked with an asterisk (*).
Tools
ftools
: Mata commands for factor variables.gtools
: A suite of commands that use hashes for a speedup over traditional stata commands.github
: Searching, installing, and managing Stata packages from GitHub.halltool
: A Stata toolbox (commands) developed by Hall.unique
: Unique values of a variable or group of variables.egenmore
: Extensions to commandgenerate
.
Data Cleaning
winsor2
: Winsorizing or Trimming variables. Devekloped by Yujun Lian.
String Functions
- *
substr
(s, n1, n2): The substring ofs
, starting atn1
, for a length ofn2
. - *
subinstr
(s1, s2, s3, n): The firstn
occurrences ins1
ofs2
will replaced withs3
. fdta
variables, from(s1) to(s2): Replacesi
withs2
in allvariables
.- *
regexm
(s,re): Evaluates to 1 if regular expressionre
is satisfied by the ASCII strings
; otherwise, 0. - *
regexr
(s, re, s2): Replaces the first substring within ASCII strings1
that matches regular expressionre
with ASCII strings2
.
Analysis & Regressions
reghdfe
: Regression with High-Dimensional Fixed Effects.ppmlhdfe
: Poisson Pseudo-Maximum Likelihood with High-Dimensional Fixed Effects.
Tabulation, Reporting, Visualization, and Documentation
esttab
: Display and export formatted regression table.asdoc
: Send Stata output to Word / RTF format.
Others
- *
which
: Display location of an ado-file. adoedit
: Open an ado-file.
Some usefule command blocks
Format long string variables
Format all long string variables to 30 characters while keeping the original format for short string variables.
1 | local chmax 30 |
If you have halltool
installed, you can do this:
1 | fmtstr |
Loop for multiple files in a folder
1 | local folder_path = "./the_folder_path" |
Remove a folder and its contents
1 | local folder = "./the_folder_path" |
shell mv
on MacOS is probably safer because you can resotre the folder from the Trash if you want to.
Comments