Ensure all required Stata packages and their specific versions are installed; similar to Python's requirements
. For a detailed guide and examples, see the related paper on arXiv.
require using ...
will now list all failed requirements instead of just the first one.require, list
renamed to require, setup
require, setup
now defaults to writing exact requirements ("reghdfe==1.2.3") instead of minimum requirements. Use the minimum
option for minimum requirements ("reghdfe>=1.2.3")list
option.To install from SSC (last updated for version 1.3.1):
ssc install require
To install from Github, type:
cap ado uninstall require
net install require, from("https://raw.githubusercontent.com/sergiocorreia/stata-require/master/src/")
To install locally, type:
cap ado uninstall require
net install require, from("c:\git\stata-require\src")
Alternatively, the lines below will install the package only if needed:
cap which require
if (c(rc)) net install require, from("https://raw.githubusercontent.com/sergiocorreia/stata-require/master/src/")
The most common usage is to use require to ensure that a minimum version is installed:
require ivreg2 >= 4.1.0
require ftools >= 2.48.0
require reghdfe>= 6.12.1
Or equivalently,
require ivreg2 >= 4.1.0 ftools >= 2.48.0 reghdfe>= 6.12.1
This will ensure that whoever runs the do-file is not using an outdated version of user packages.
You can also require exact versions:
require ivreg2 == 4.1.0
And install missing packages automatically if needed:
require ivreg2 >= 4.1.0 , install
require ftools >= 2.48.0 , install from("https://github.com/sergiocorreia/ftools/raw/master/src/")
require reghdfe>= 6.12.1 , install from(https://github.com/sergiocorreia/reghdfe/raw/master/src/)
Lastly, you can just use it to ensure the package is installed without specifying a version:
require ivreg2
Require an exact version, using Github tags (WIP):
require reghdfe == 6.12.1 , install from(https://github.com/sergiocorreia/reghdfe/releases)
For large projects, such as a research paper, the recommended usage is to first create a requirements.txt
file:
<<< contents of requirements.txt <<<<
# SSC requirements
mdesc >= 0.9.4 , from(ssc)
winsor2 >= 1.1 , from(ssc)
coefplot >= 1.8.4 , from(ssc)
# Github/etc requirements
rdrobust >= 8.1 , from(https://raw.githubusercontent.com/rdpackages/rdrobust/master/stata)
rddensity >= 1.0 , from(https://raw.githubusercontent.com/rdpackages/rddensity/master/stata)
lpdensity >= 1.0 , from(https://raw.githubusercontent.com/nppackages/lpdensity/master/stata)
>>>
And then add this line to the top of every do-file (or at the beginning of a master do-file):
require using "requirements.txt", install
We also encourage users to manage their folders with the setroot
package (based on here
by Miklós Koren).
As discussed in our accompanying paper, one of our key goals was to successfully match as many user-contributed as possible, particularly those user widely by researchers. Figure 2 from the paper (below) illustrates the package performance as of version 1.1.