Most recent update: 2023-10-27
specurve is a Stata command for Specification Curve Analysis.
Installation & update
Run the following command in Stata:
net install specurve, from("https://raw.githubusercontent.com/mgao6767/specurve/master") replace
Example usage & output
. use "http://www.stata-press.com/data/r13/nlswork.dta", clear . copy "https://mingze-gao.com/specurve/example_config_nlswork_reghdfe.yml" ., replace
. specurve using example_config_nlswork_reghdfe.yml, saving(specurve_demo)
The output is
[specurve] 11:43:54 - 84 total specifications to estimate. [specurve] 11:43:54 - Estimating model 1 of 84 [specurve] 11:43:54 - Estimating model 2 of 84 ...... [specurve] 11:43:57 - Estimating model 84 of 84 [specurve] 11:43:57 - 81 out of 84 models have point estimates significant at 1% level. [specurve] 11:43:57 - 84 out of 84 models have point estimates significant at 5% level. [specurve] 11:43:57 - Plotting specification curve... file specurve_demo.gph saved [specurve] 11:43:58 - Completed. [specurve] use frame change specurve to see results [specurve] use frame change default to switch back to current frame
In this example, we
- turn off the benchmark line,
- set the number of decimals to display to 4,
- set the number of y-axis ticks/labels to 8, and
- display the coefficients in descending order.
. specurve using example_config_nlswork_reghdfe.yml, nob yticks(8) rounding(.0001) desc
IV regressions with
. copy "https://mingze-gao.com/specurve/example_config_nlswork_ivreghdfe.yml" ., replace . specurve using example_config_nlswork_ivreghdfe.yml, cmd(ivreghdfe) rounding(0.01) title("IV regression with ivreghdfe")
help specurve in Stata for a step-by-step guide.
Estimation results are saved in the frame named "specurve".
frame change specurve to check the results.
frame change default to switch back to the original dataset.
specurve using filename, [width(real) height(real) realativesize(real) scale(real) title(string) saving(name) name(string) descending outcmd output benchmark(real) nobenchmark rounding(real) yticks(int) ymin(real) ymax(real) cmd(name) keepsingletons]
|width(real)||set width of the specification curve plot.|
|height(real)||set height of the specification curve plot.|
|relativesize(real)||set the size of coefficients panel relative to the entire plot. Defaults to 0.6.|
|scale(real)||resize text, markers, and line widths.|
|title(string)||set graph title.|
|saving(name)||save graph as name.|
|name(string)||set graph title as string.|
|descending||plot coefficients in descending order.|
|outcmd||display the full regression command.|
|output||display all regression outputs.|
|benchmark(real)||set the benchmark level. Defaults to 0.|
|nobenchmark||turnoff the benchmark line|
|rounding(real)||set the rounding of y-axis labels and hence number of decimal places to display. Defaults to 0.001.|
|yticks(int)||set the number of ticks/labels to display on y-axis. Defaults to 5.|
|ymin(real)||set the min tick of y-axis. Default is automatically set.|
|ymax(real)||set the max tick of y-axis. Default is automatically set.|
|cmd(name)||set the command used to estimate models. Defaults to
|keepsingletons||keep singleton groups. Only useful when using
- Fix a bug about y-axis labels display due to early rounding.
- Added options
ymaxto manually specify the range of y-axix.
- Thanks to Jonas Happel from Frankfurt School of Finance & Management for suggesting the feature.
- Added an option to turn off benchmark line.
- Added an option to decide the number of ticks and labels on the y-axis.
- Thanks to John Iselin from University of Maryland for suggesting the features.
- Added a dependency check for
- Thanks to Brittany O'Duffy from Oxford Internet Institute at University of Oxford for identifying the bug.
- Fix a bug that mistakes the hashtag in Stata interactions (e.g.,
var1#var2) for inline comments.
- Thanks to Kenneth Shores from University of Delaware for identifying the bug and suggesting solutions.
- Preserve the order of choices in each group as specified in the configuration file.
- Allow no conditions specified in the configuration file.
- Thanks to Christopher Whaley from RAND Corp for suggesting the improvement.
- Thanks to Ken P.Y. Wang from National Taiwan University for suggesting the improvement.
- Remove Python dependencies.
- Thanks to Germán Guerra from the National Institute of Public Health (Mexico), Kausik Chaudhuri from University of Leeds for numerous installation tests which ultimately lead me to rewrite
specurvein pure Stata.
- When following the help file, Stata reports error "file example_config_nlswork_1.yml could not be opened".
This is mostly due to permission error. Stata does not have write permission to the current working directory so it cannot download the example configuration file. You can solve it by changing the working directory to somewhere else.
Uri Simonsohn, Joseph Simmons and Leif D. Nelson for their paper "Specification Curve Analysis" (Nat Hum Behav, 2020, and previous working paper), first suggesting the specification curve.
Rawley Heimer from Boston College who visited our discipline in 2019 and introduced the Specification Curve Analysis to us in the seminar on research methods.
This Stata command was originally developed when writing my first paper, Gao, M., Leung, H., & Qiu, B. (2021) "Organization capital and executive performance incentives" at the Journal of Banking & Finance.
The earlier version depends on Stata 16's Python integration and a range of external Python packages, which has caused many compatibility issues.
The current version has removed Python dependency and implements everything from parsing configuration file, composing specifications, estimating models, to plotting specification curve in Stata Mata.
If there's any issue (likely), please contact me at firstname.lastname@example.org