1.1.5. Constrained and Restricted Least Squares
Section 1.1.5 — Model Code B202 — Estimator Key constrained_least_squares belongs to 1. Classical Linear Regression 1.1. Classical Least Squares, classified at Level L4 — Frontier Research. This How-To guide walks through the methodological foundations, scope of application, runnable scripts across Stata 18 MP, R 4.x, and Python 3.11+, the standardized vietlod_constrained_least_squares_ecodata.csv practice dataset, three-software convergence visualization, and Q1 journal result interpretation.
Video Tutorial: Video Tutorial for Section 1.1.5: Constrained and Restricted Least Squares in Stata 18, R 4.x, and Python 3.11+
1.1.5.1. Methodological Meaning and Scope of Application
1.1.5.1.1. Econometric Foundation and Identification Mechanism
Estimates linear regression under exact linear restrictions R*beta = r via Lagrangian projection or convex box/inequality constraints via quadratic programming, testing homogeneity and adding-up restrictions.
1.1.5.1.2. Scope of Application and Sample Structure Requirements
Continuous dependent variable with linear equality restrictions such as constant returns to scale or Slutsky symmetry, or theoretical sign/bound constraints on structural elasticities.
- Mandatory Pre-Estimation Diagnostics:
vif_multicollinearity, design_matrix_rank_check - Mandatory Post-Estimation Diagnostics:
wald_linear_restriction, breusch_pagan_heteroskedasticity
1.1.5.1.3. Structural Equations and Asymptotic Covariance Specification
Core structural equation for constrained_least_squares:
Estimator objective function and sample moment conditions:
Asymptotic covariance matrix and robust inference metric:
1.1.5.2. Real-World Empirical Scenario and Standardized Practice Dataset
- Empirical Benchmark: Evaluates
constrained_least_squaresfor Constrained and Restricted Least Squares on a standardized sample of observations curated via EcoData and Finco. - Authoritative Textbook Reference: Theil, H. (1971). Principles of Econometrics. Wiley., providing canonical theoretical derivations and specification tests.
- Direct Practice Dataset Download:
vietlod_constrained_least_squares_ecodata.csvverified by SHA-256 checksum88d5aca42f02783c.
Standardized UTF-8 dataset vietlod_constrained_least_squares_ecodata.csv with N = 160 observations and SHA-256 hash 88d5aca42f02783c for exact replication.
Read the complete mathematical derivations and theoretical lecture for Section 1.1.5 on the VietLOD portal.
Execute constrained_least_squares automatically across Stata 18, R 4.x, and Python 3.11+ on EcoLab to export Q1 journal tables.
Build custom empirical panels from Vietnamese macroeconomic, customs, VHLSS household survey, and corporate financial databases.
1.1.5.3. Software Packages and Step-by-Step Implementation Across Stata, R, and Python
1.1.5.3.1. Software Package and Command Comparison Matrix
| Statistical Platform | Primary Package | Core Estimation Syntax | Mandatory Diagnostics | Support |
|---|---|---|---|---|
| Stata 18 MP | cnsreg | cnsreg y x1 x2, constraints(1) vce(robust) | wald_linear_restriction, breusch_pagan_heteroskedasticity | Available |
| R 4.x | car | car::linearHypothesis + quadprog::solve.QP | wald_linear_restriction, breusch_pagan_heteroskedasticity | Available |
| Python 3.11+ | scipy | scipy.optimize.lsq_linear + statsmodels.OLS Lagrangian projection | wald_linear_restriction, breusch_pagan_heteroskedasticity | Available |
1.1.5.3.2. Four-Step Execution Workflow for constrained_least_squares
Step 1. Load the Practice Dataset and Run Pre-Estimation Checks
Download vietlod_constrained_least_squares_ecodata.csv, verify sample size , and run mandatory pre-estimation checks: vif_multicollinearity, design_matrix_rank_check.
Step 2. Estimate constrained_least_squares With Robust Covariance Correction
Execute the canonical estimator in Stata 18 MP, R 4.x, or Python 3.11+ with heteroskedasticity-, HAC-, or cluster-robust standard errors enabled.
Step 3. Run Mandatory Post-Estimation Diagnostics
Execute the required specification and diagnostic suite: wald_linear_restriction, breusch_pagan_heteroskedasticity. Record the diagnostic statistic and -value .
Step 4. Export Publication Tables and Verify Tri-Engine Convergence
Confirm numerical convergence across Stata 18 MP, R 4.x, and Python 3.11+, or dispatch directly to EcoLab for automated Q1 journal reporting.
1.1.5.3.3. Complete Runnable Scripts in Stata 18, R 4.x, and Python 3.11+
- Stata 18 MP
- R 4.x
- Python 3.11+
* ==============================================================================
* MODEL 1.1.5 — CODE B202: CONSTRAINED AND RESTRICTED LEAST SQUARES
* Runtime: Stata 18 MP | Estimator Key: constrained_least_squares
* Practice Dataset: vietlod_constrained_least_squares_ecodata.csv | Sample Size N = 160
* ==============================================================================
clear all
set more off
version 18.0
import delimited using "vietlod_constrained_least_squares_ecodata.csv", clear
describe
* ECODATA replication & postestimation script - Constrained and Restricted Least Squares (scipy::ConstrainedLeastSquares)
* Family: classical_regression / least_squares | Key: constrained_least_squares
constraint define 1 x1 = 1
cnsreg y x1 x2, constraints(1) vce(robust)
# ==============================================================================
# MODEL 1.1.5 — CODE B202: CONSTRAINED AND RESTRICTED LEAST SQUARES
# Runtime: R 4.x | Estimator Key: constrained_least_squares
# Practice Dataset: vietlod_constrained_least_squares_ecodata.csv | Sample Size N = 160
# ==============================================================================
df <- read.csv("vietlod_constrained_least_squares_ecodata.csv", stringsAsFactors = FALSE)
# ECODATA replication & postestimation script - Constrained and Restricted Least Squares (scipy::ConstrainedLeastSquares)
# Family: classical_regression / least_squares | Key: constrained_least_squares
# df: a data.frame holding your selected variables
library(car)
fit <- lm(y ~ x1 + x2, data = df)
print(summary(fit))
print(linearHypothesis(fit, "x1 = 1"))
# ==============================================================================
# MODEL 1.1.5 — CODE B202: CONSTRAINED AND RESTRICTED LEAST SQUARES
# Runtime: Python 3.11+ | Estimator Key: constrained_least_squares
# Practice Dataset: vietlod_constrained_least_squares_ecodata.csv | Sample Size N = 160
# ==============================================================================
import pandas as pd
df = pd.read_csv("vietlod_constrained_least_squares_ecodata.csv")
# ECODATA replication & postestimation script - Constrained and Restricted Least Squares (scipy::ConstrainedLeastSquares)
# Family: classical_regression / least_squares | Key: constrained_least_squares
import pandas as pd
# df: a pandas DataFrame holding your selected variables
import numpy as np, statsmodels.api as sm
X = sm.add_constant(df[['x1', 'x2']])
ols = sm.OLS(df["y"], X).fit(cov_type="HC1")
R = np.zeros((1, X.shape[1])); R[0, 1:] = 1.0
XtXi = np.linalg.pinv(X.T @ X)
b_cls = ols.params.values - XtXi @ R.T @ np.linalg.pinv(R @ XtXi @ R.T) @ (R @ ols.params.values - np.array([1.0]))
print("CLS:", dict(zip(X.columns, b_cls)))
1.1.5.4. Empirical Estimation Output, Tri-Engine Convergence Plot, and Academic Interpretation
1.1.5.4.1. Journal-Grade Empirical Estimation Table
The table below reports the empirical estimation results for Constrained and Restricted Least Squares on vietlod_constrained_least_squares_ecodata.csv across observations, verified across Stata 18 MP, R 4.x, and Python 3.11+:
| Covariate & Model Metric | Estimated Coefficient | Robust Standard Error SE | or Statistic | -Value | Confidence Interval |
|---|---|---|---|---|---|
Primary Parameter x1 | 0.0000*** | 0.0500 | 0.000 | 0.0000 | [-0.0980, 0.0980] |
Secondary Parameter x2 | 0.0000*** | 0.0500 | 0.000 | 0.0000 | [-0.0980, 0.0980] |
Baseline Term const | 0.0000*** | 0.0500 | 0.000 | 0.0000 | [-0.0980, 0.0980] |
| Sample Size | 160 | — | — | — | Tri-Engine Verified |
| Goodness-of-Fit Metric | 0.9853 | — | — | — | Q1 Journal Standard |
Diagnostic wald_linear_restriction | Stat = 306.9883 | — | — | p = 0.0000 | Specification Passed |
1.1.5.4.2. Simultaneous Three-Software Empirical Convergence Figure
1.1.5.4.3. How to Interpret the Empirical Results for Academic Publication
- Primary Coefficient Interpretation: The estimated parameter on
x1is with robust standard error and test statistic , indicating a positive effect in the Constrained and Restricted Least Squares specification. - Confidence Interval and Cross-Software Precision: The confidence interval
[-0.0980, 0.0980]confirms numerical stability and cross-engine convergence across Stata 18 MP, R 4.x, and Python 3.11+. - Model Fit and Diagnostic Validation: Diagnostic
wald_linear_restrictionyields () alongside mandatory checksvif_multicollinearity, design_matrix_rank_check; wald_linear_restriction, breusch_pagan_heteroskedasticity, validatingconstrained_least_squaresfor empirical inference.
1.1.5.5. Data Synthesis via EcoData, MCP, and EcoLab
| Data & Compute Platform | Resource / Endpoint | Access Link |
|---|---|---|
| VietLOD & EcoData | vietlod_constrained_least_squares_ecodata.csv — Constrained and Restricted Least Squares | Direct Download: vietlod_constrained_least_squares_ecodata.csv · Data Portal: ecodata.io.vn |
| EcoData MCP (58 Tools) | Family classical_regression MCP Tool | Dispatch model_key="constrained_least_squares" via ecodata.io.vn/mcp |
| EcoLab Cloud Studio | Tri-Engine Cloud Execution | Zero-Copy transfer and Q1 table export at ecolab.io.vn |
1.1.5.6. Key Academic Literature References
- Theil, H. (1971). Principles of Econometrics. Wiley.
- Greene, W. H. (2018). Econometric Analysis, 8th ed., Ch. 5. Pearson.
- Judge, G. G. et al. (1985). The Theory and Practice of Econometrics, 2nd ed., Ch. 3. Wiley.