Statistics · Linear Programming Regression

LP_REGRESSION

Estimate robust median relationships as a linear program, impose economic restrictions directly on coefficients, and test whether those restrictions hold only within a dated policy or economic regime.

Least absolute deviations Median regression Coefficient constraints Dated regime effects Primal and dual Observation shadow prices

Command family

LP_REGRESSION(LIST(dependent,predictor1,predictor2,...))
LP_ADD_EQUATION(model,"coefficient_expression")
LP_ADD_PERIOD_EQUATION(model,"coefficient_expression",start_yyyymmdd,end_yyyymmdd)
SLIDESHOW(model)
The first series in LIST is the dependent variable. Every remaining series is a predictor. RainbowStats aligns the dates and includes an intercept automatically.

What it estimates

Ordinary least squares minimizes squared errors and therefore gives large residuals disproportionate influence. LP_REGRESSION minimizes absolute errors. At the default quantile of 0.50, it estimates the conditional median of the dependent variable.

minimize  Σ |yi − xi′β|

Median regression is especially useful when a series contains shocks, heavy tails, unequal variance, or isolated observations that should not dominate the fitted relationship.

Why this is a linear program

Each residual is split into nonnegative positive and negative components. Each unrestricted coefficient is similarly written as the difference of two nonnegative variables.

yi = xi′β + ui+ − ui
βj = βj+ − βj
minimize  ½Σ(ui+ + ui)

The objective and every equation remain linear, allowing RainbowStats to use the same transparent simplex machinery as its general LP commands.

Basic example: inflation, unemployment, and the policy rate

Inflation=SET_NAME(TOQUARTERLY(100*(CPIAUCSL/LAG(CPIAUCSL,12)-1)),"Inflation")
Unemployment=SET_NAME(TOQUARTERLY(UNRATE),"Unemployment")
PolicyRate=SET_NAME(TOQUARTERLY(FEDFUNDS),"PolicyRate")

R=LP_REGRESSION(LIST(Inflation,Unemployment,PolicyRate))
SLIDESHOW(R)

This estimates the median quarterly relationship between year-over-year inflation, unemployment, and the federal funds rate. The command names supplied by SET_NAME also become the coefficient names used in later constraint equations.

A coefficient is an estimated conditional association, not automatically a causal effect. A positive policy-rate coefficient may reflect the Federal Reserve raising rates in response to inflation rather than rates causing inflation.

Global coefficient constraints

R=LP_REGRESSION(LIST(Inflation,Unemployment,PolicyRate))
LP_ADD_EQUATION(R,"Unemployment<0")
SLIDESHOW(R)

The inequality restricts the unemployment coefficient over the entire sample. Because linear programs use closed feasible regions, < and > are interpreted as ≤ and ≥.

If the unrestricted coefficient is positive, the restricted optimum will often place it exactly at zero. A coefficient on its boundary is evidence that the restriction is binding—not that the data independently estimated an exact zero.

Dated period constraints

R=LP_REGRESSION(LIST(Inflation,Unemployment,PolicyRate))
LP_ADD_PERIOD_EQUATION(R,"Unemployment<0",20200101,20211231)
SLIDESHOW(R)

A period equation does not constrain the full-sample coefficient. It adds a regime interaction that is active only from the start date through the end date, both inclusive.

period coefficient = base coefficient + period adjustment

Outside the interval, the base coefficient applies. Inside the interval, the effective coefficient includes the estimated adjustment and must satisfy the stated restriction.

Reading a period-constrained result

Reported rowInterpretationIllustrative value
Unemployment Estimated unemployment coefficient outside the dated regime. +0.032378
Unemployment_20200101_20211231_Adjustment Change applied only during the specified period. −0.032378
Unemployment_20200101_20211231_Effective Base plus adjustment: the coefficient operating during the period. 0
In this illustration, the period adjustment exactly offsets the positive base estimate. The COVID-period restriction is binding while the relationship outside the period remains free to be positive.

Primal and dual methodology

For quantile τ and observation weights wi, the primal model is:

minimize  Σwi[τui+ + (1−τ)ui]
subject to  Xβ + u+ − u = y

For an unconstrained coefficient model, the exact dual is:

maximize  y′a
subject to  X′a = 0,  (τ−1)wi ≤ ai ≤ τwi

Equality of the primal and dual objectives provides a numerical strong-duality check on the solution.

Slideshow panels

PanelWhat it shows
ModelStatus, quantile, dimensions, objective values, duality gap, and mean absolute error.
CoefficientsBase estimates plus period adjustments and effective period coefficients.
FitActual, fitted, and residual values for aligned observations.
ShadowObservation-level dual sensitivity for an unconstrained model.
TableauPrimal decision variables, equations, activities, slack, and binding status.
DualThe explicit dual LP when the simple unconstrained dual applies.
EquationsThe objective and generated observation, coefficient, and period equations.

Where it is useful

  1. Estimate macroeconomic relationships without allowing crisis outliers to dominate squared-error loss.
  2. Impose sign or magnitude restrictions suggested by economic theory.
  3. Test whether a restriction applies only during COVID, zero-rate policy, tightening, recession, or another dated regime.
  4. Compare an unrestricted empirical relationship with a theory-constrained alternative.
  5. Inspect which observations have the greatest local influence through the dual shadow prices.

Period-model safeguards

  • Dates use integer YYYYMMDD format.
  • The start and end dates are inclusive.
  • At least two aligned observations must exist inside the period.
  • At least two aligned observations must remain outside the period.
  • Multiple restrictions may use the exact same interval.
  • Partially overlapping intervals are not supported in the initial implementation.
A short regime can produce an unstable adjustment even when the LP has a mathematically valid optimum. Economic interpretation still requires an adequate number of observations and meaningful variation within the period.

Interpretation and limitations

IssueGuidance
Not OLSThe objective is absolute or quantile loss. OLS standard errors, t-statistics, and R² do not carry over automatically.
No automatic causalityContemporaneous macroeconomic coefficients often combine behavior, policy reactions, expectations, and feedback.
ScalingRescale very large or very small predictors when numerical magnitudes differ substantially.
CollinearityHighly related predictors can make individual coefficient decompositions unstable or non-unique.
Binding restrictionsA coefficient at a boundary reflects the imposed feasible region and should be identified as constrained.
Regime choiceDate intervals should follow a defensible event or hypothesis, not repeated searching for a preferred result.
LP_REGRESSION estimates a constrained statistical relationship. It does not allocate capital or maximize investment returns. Use the RainbowStats linear-programming model builder when the variables themselves represent allocations, production, financing, or other decisions.