█████╗██████╗ █████╗ █████╗ ██╗ ██████╗
██╔═══╝╚═██╔═╝██╔══██╗██╔══██╗██║ ██╔═══╝
██║ ██║ ██║ ██║██║ ██║██║ ██████╗
██║ ██║ ██║ ██║██║ ██║██║ ╚═══██║
╚█████╗ ██║ ╚█████╔╝╚█████╔╝█████╗██████║
╚════╝ ╚═╝ ╚════╝ ╚════╝ ╚════╝╚═════╝
some really fast Stata programs
This is an initial release. Please report problems/suggestions on Issues.
ctools provides really fast implementations of common Stata routines. The syntax is largely unchanged from the commands they replace, sometimes with additional features; see the compatibility table.
| Stata command | Replaced with | Description | Approx. speedup¹ |
|---|---|---|---|
import |
cimport |
Import text, Excel, dBase, SAS, SPSS, and shapefiles | 30–50× |
export |
cexport |
Export text, Excel, dBase, SAS, SPSS, and shapefiles | 40–60× |
sort |
csort |
Sort dataset | 1–3× |
merge |
cmerge |
Merge (join) datasets | 1–7× |
sample |
csample |
Resampling without replacement | 5–8× |
bsample |
cbsample |
Resampling with replacement | 3–4× |
encode |
cencode |
Recast string as labeled numeric | 15–60× |
decode |
cdecode |
Recast labeled numeric as string | 1–10× |
destring |
cdestring |
Recast string as numeric type | 40× |
ipolate |
cipolate |
Linear interpolation and extrapolation | 10–12× |
split |
csplit |
Split strings into fields | 15–18× |
rangejoin |
crangejoin |
Join observations within inclusive intervals | 10-15× |
qreg |
cqreg |
Quantile regression | 5–6× |
gstats winsor |
cwinsor |
Winsorize variables | 1.5–2× |
rangestat |
crangestat |
Range statistics of variables | 80–110× |
psmatch2 |
cpsmatch |
Propensity score matching | 1.5–2.5× |
binscatter |
cbinscatter |
Binned scatter plots | 5–10× |
reghdfe |
creghdfe |
OLS with multi-way fixed effects | 9.0–13.0× |
ivreghdfe |
civreghdfe |
2SLS/GMM with multi-way fixed effects | 14–16× |
ppmlhdfe |
cpplmhdfe |
PPML with multi-way fixed effects | 5–6× |
¹ Approximate speedups from three benchmarks with 1M, 10M, and 25M observations and 20 mixed-type variables. Import/export timings use CSV. Values below 1× mean ctools was slower. Your mileage may vary. See benchmark details and results.
Requires Stata 14.1 or later. In Stata:
net install ctools, from("https://raw.githubusercontent.com/mdroste/stata-ctools/main/build") replace- Command features, usage examples, and Stata's
help <command>. - Compatibility and limitations, including supported options and numerical differences.
- Installation and building from source and the developer guide.
99.9% of this code was written by LLMs. The early stuff was written in January 2026 by Claude Opus 4.5 and ChatGPT 5.2; recent bugfixes and improvements were written by Claude Fable 5.1, Claude Opus 5.5, and GPT 6.0 Astra/Sol.
- Sergio Correia for ftools, reghdfe, and ivreghdfe (with Lars Vilhuber), as well as tons of helpful comments and suggestions
- Mauricio Caceres Bravo for gtools and invaluable contributions to cowsay
- Christopher (Kit) Baum, Mark E Schaffer, and Steven Stillman for ivreg2
- Robert Picard, Nicholas J. Cox, and Roberto Ferrer for rangestat
- Sascha Witt for the In-place Parallel Super Scalar Samplesort (IPS⁴o) sorting algorithm.
- Claude Code
Project code is MIT-licensed. The distribution includes third-party notices.
Contributions are welcome. Please open an Issue or submit a pull request.
0 comments
log in to comment.