Stata 101 - Packages
If you've ever used Python, you may know that it's famous for its simplicity and the many packages available for use. Good news is, Stata is no different. We can install a wide range of Stata packages easily and then use them to achieve a ton of things.
This post briefly explains where to find, how to install and update Stata packages.
Table of Contents
- Stata packages
- Where to find Stata packages
- How to install and update packages
- Some packages of my choice
In a nutshell, installing and using Stata packages are as simple as the following two lines of code (and a line of output):
. ssc install nicewords . nicewords Absolutely excellent!
Specifically, we use the builin command
ssc to install a package named
nicewords in the first line, and then execute the command
nicewords in the second line, which randomly prints some nice words.
Generally, a package can provide one or more Stata commands to use, depending on the complexity of the task it sovles.
Where to find Stata packages
ssc - Statistical Software Components Archive
Stata packages are hosted at the Statistical Software Components (SSC) Archive, which is often called the Boston College Archive and provided by http://repec.org. This explains the example above where we used the command
ssc to manage (install) packages.
We can find recently added packages with
. ssc new, and the top 10 most popular packages on SSC with
. ssc hot. In fact, the top 10 for December 2022 are:
net - e.g., GitHub
Apart from SSC, some packages are available on other websites like GitHub. A growing trend is that package authors publish their code repositories on GitHub, which contain the devlopment version of the packages.
How to install and update packages
ssc install is pretty much all we need. For example, to install the package
. ssc install reghdfe
For packages outside SSC, we can install them using
net. As an example, I have a package
specurve on GitHub, which can be installed by:
. net install specurve, from("https://raw.githubusercontent.com/mgao6767/specurve/master")
To update an existing package, we can add the option
replace to the above command:
. ssc install reghdfe, replace . net install specurve, replace from("https://raw.githubusercontent.com/mgao6767/specurve/master")
Alternatively, we can use
. ado update, update // for community-contributed packages . ado update, update ssconly // for SSC only
Some packages of my choice
reghdfe is among the top 10 Stata packages as we've seen above. It allows for multiple fixed effects in linear regressions, while the builtin
xtreg allows only one fixed effect. It's gold!
ivreghdfe is essentially
ivreg2, which allows us to include multiple fixed effects in instrumental variable regressions.
estout is also a top 10 Stata package that provides tools to make regression tables. We've seen an example from the previous post. I highly recommend, too!
outreg2 does a similar job in a simpler way. Yet if we want finner controls
estout is perhaps better, in my humble opinion.
Data is often noisy with extreme values or impossible values recorded by mistake. In some fields of research, we try to mitigate such concern by winsorization. Note that they may yield different results due to their different approaches in determinining percentile values.