Greeners: High-Performance Econometrics in Rust
Greeners is a lightning-fast, type-safe econometrics library written in pure Rust. It provides a comprehensive suite of estimators for Cross-Sectional, Time-Series, and Panel Data analysis, leveraging linear algebra backends (LAPACK/BLAS) for maximum performance.
Designed for academic research, heavy simulations, and production-grade economic modeling.
✨ NEW: R/Python-Style Formula API
Greeners now supports R/Python-style formula syntax (like statsmodels and lm()), making model specification intuitive and concise:
use ;
// Python equivalent: smf.ols('y ~ x1 + x2', data=df).fit(cov_type='HC1')
let formula = parse?;
let result = OLSfrom_formula?;
All estimators support formulas: OLS, WLS, DiD, IV/2SLS, Logit/Probit, Quantile Regression, Panel Data (FE/RE/Between), and more!
📖 See FORMULA_API.md for complete documentation and examples.
🚀 Features
Cross-Sectional & General
- OLS & GLS: Robust standard errors (White, Newey-West).
- IV / 2SLS: Instrumental Variables for endogeneity correction.
- Quantile Regression: Robust estimation via Iteratively Reweighted Least Squares (IRLS).
- Discrete Choice: Logit and Probit models (Newton-Raphson MLE).
- Diagnostics: R-squared, F-Test, T-Test, Confidence Intervals.
Time Series (Macroeconometrics)
- Unit Root Tests: Augmented Dickey-Fuller (ADF).
- VAR (Vector Autoregression): Multivariate modeling with Information Criteria (AIC/BIC).
- VARMA: Hannan-Rissanen algorithm for ARMA structures.
- VECM (Cointegration): Johansen Procedure (Eigenvalue decomposition) for I(1) systems.
- Impulse Response Functions (IRF): Orthogonalized structural shocks.
Panel Data
- Fixed Effects (Within): Absorbs individual heterogeneity.
- Random Effects: Swamy-Arora GLS estimator.
- Between Estimator: Long-run cross-sectional relationships.
- Dynamic Panel: Arellano-Bond (Difference GMM) to solve Nickell Bias.
- Panel Threshold: Hansen (1999) non-linear regime switching models.
- Testing: Hausman Test for FE vs RE.
Systems of Equations
- SUR: Seemingly Unrelated Regressions (Zellner).
- 3SLS: Three-Stage Least Squares (System IV).
System Requirements (Pre-requisites)
Debian / Ubuntu / Pop!_OS:
Fedora / RHEL / CentOS:
Arch Linux / Manjaro:
macOS:
📦 Installation
Add this to your Cargo.toml:
[]
= "0.1.1"
= "0.15"
# Note: You must have a BLAS/LAPACK provider installed on your system
= { = "0.14", = ["openblas"] }
🎯 Quick Start
Loading Data from CSV (NEW!)
use ;
Using Formula API (R/Python Style)
use ;
use Array1;
use HashMap;
Traditional Matrix API
use ;
use ;
📚 Formula API Examples
Difference-in-Differences
use ;
// Python: smf.ols('outcome ~ treated + post + treated:post', data=df).fit(cov_type='HC1')
let formula = parse?;
let result = from_formula?;
Instrumental Variables (2SLS)
use ;
// Endogenous equation: y ~ x1 + x_endog
// Instruments: z1, z2
let endog_formula = parse?;
let instrument_formula = parse?;
let result = IVfrom_formula?;
Logit/Probit
use ;
// Binary choice models
let formula = parse?;
let logit_result = from_formula?;
let probit_result = from_formula?;
Panel Data (Fixed Effects)
use ;
let formula = parse?;
let result = from_formula?;
Quantile Regression
use ;
// Median regression
let formula = parse?;
let result = from_formula?;
🔧 Formula Syntax
- Basic:
y ~ x1 + x2 + x3(with intercept) - No intercept:
y ~ x1 + x2 - 1ory ~ 0 + x1 + x2 - Intercept only:
y ~ 1
All formulas follow R/Python syntax for familiarity and ease of use.
📖 Documentation
- FORMULA_API.md - Complete formula API guide with Python/R equivalents
- examples/ - Working examples for all estimators
csv_formula_example.rs- Load CSV files and run regressionsformula_example.rs- General formula API demonstrationdid_formula_example.rs- Difference-in-Differences with formulasquickstart_formula.rs- Quick start example
Run examples:
🎯 Why Greeners?
- Familiar Syntax: R/Python-style formulas make transition seamless
- Type Safety: Rust's type system catches errors at compile time
- Performance: Native speed with BLAS/LAPACK backends
- Comprehensive: Full suite of econometric estimators
- Production Ready: Memory safe, no garbage collection pauses