Skip to main content

Elastic Net — L1 + L2 regularization

Elastic Net combines the L1 penalty (Lasso) and the L2 penalty (Ridge). It both selects variables (like Lasso) and handles highly correlated variable groups well (like Ridge) — fixing Lasso's instability under correlation.

When to use

Use Elastic Net when you have many variables and there are groups of highly correlated variables that you want to keep/drop together rather than picking one at random.


Model specification

minβ  i=1n(YiXiβ)2+λ[αjβj+(1α)jβj2]\min_{\beta} \; \sum_{i=1}^{n} (Y_i - X_i \beta)^2 + \lambda \left[ \alpha \sum_{j} |\beta_j| + (1-\alpha) \sum_{j} \beta_j^2 \right]
  • α[0,1]\alpha \in [0,1] is the mixing ratio: α=1\alpha = 1 ⇒ Lasso; α=0\alpha = 0 ⇒ Ridge.
  • λ\lambda controls the total penalty.

Running in EcoLab

  1. Modeling module → Regularized regression family → Elastic Net.
  2. Select YY, the XX variables; standardize; choose α\alpha and λ\lambda (2-D grid CV).
  3. Read the retained variables + coefficients; export the replication code.

Replication code

* ---- Elastic Net with cross-validation ----
use "macro_data.dta", clear

elasticnet linear y x1-x20, selection(cv) alphas(0.5)

* Display selected coefficients
lassocoef, display(coef, standardized)

Limitations

  • Has two tuning parameters (α\alpha, λ\lambda) ⇒ heavier CV.
  • Still a prediction-oriented method; causal interpretation requires care.

Video tutorial

Video Tutorial: Running Elastic Net in EcoLab

See also