**[R] cnsreg** -- Constrained linear regression

__Syntax__

**cnsreg** *depvar* *indepvars* [*if*] [*in*] [*weight*] **,** __c__**onstraints(***constraints***)**
[*options*]

*options* Description
-------------------------------------------------------------------------
Model
* __c__**onstraints(***constraints***)** apply specified linear constraints
__col__**linear** keep collinear variables
__nocons__**tant** suppress constant term

SE/Robust
**vce(***vcetype***)** *vcetype* may be **ols**, __r__**obust**, __cl__**uster**
*clustvar*, __boot__**strap**, or __jack__**knife**

Reporting
__l__**evel(***#***)** set confidence level; default is **level(95)**
__nocnsr__**eport** do not display constraints
*display_options* control columns and column formats, row
spacing, line width, display of omitted
variables and base and empty cells, and
factor-variable labeling

__ms__**e1** force MSE to be 1
__coefl__**egend** display legend instead of statistics
-------------------------------------------------------------------------
* **constraints(***constraints***)** is required.
*indepvars* may contain factor variables; see fvvarlist.
*depvar* and *indepvars* may contain time-series operators; see tsvarlist.
**bootstrap**, **by**, **fp**, **jackknife**, **mi estimate**, **rolling**, **statsby**, and **svy** are
allowed; see prefix.
**vce(bootstrap)** and **vce(jackknife)** are not allowed with the **mi estimate**
prefix.
With the **fp** prefix, constraints cannot be specified for the variable
containing fractional polynomial terms.
Weights are not allowed with the **bootstrap** prefix.
**aweight**s are not allowed with the **jackknife** prefix.
**vce()**, **mse1**, and weights are not allowed with the **svy** prefix.
**aweight**s, **fweight**s, **iweight**s, and **pweight**s are allowed; see weight.
**mse1** and **coeflegend** do not appear in the dialog box.
See **[R] cnsreg postestimation** for features available after estimation.

__Menu__

**Statistics > Linear models and related > Constrained linear regression**

__Description__

**cnsreg** fits constrained linear regression models.

__Options__

+-------+
----+ Model +------------------------------------------------------------

**constraints(***constraints***)**, **collinear**, **noconstant**; see **[R] estimation**
**options**.

+-----------+
----+ SE/Robust +--------------------------------------------------------

**vce(***vcetype***)** specifies the type of standard error reported, which
includes types that are derived from asymptotic theory (**ols**), that
are robust to some kinds of misspecification (**robust**), that allow for
intragroup correlation (**cluster** *clustvar*), and that use bootstrap or
jackknife methods (**bootstrap**, **jackknife**); see **[R] ***vce_option*.

**vce(ols)**, the default, uses the standard variance estimator for
ordinary least-squares regression.

+-----------+
----+ Reporting +--------------------------------------------------------

**level(***#***)**; see **[R] estimation options**.

**nocnsreport**; see **[R] estimation options**.

*display_options*: **noci**, __nopv__**alues**, __noomit__**ted**, **vsquish**, __noempty__**cells**,
__base__**levels**, __allbase__**levels**, __nofvlab__**el**, **fvwrap(***#***)**, **fvwrapon(***style***)**,
**cformat(***%fmt***)**, **pformat(%***fmt***)**, **sformat(%***fmt***)**, and **nolstretch**; see **[R]**
**estimation options**.

The following options are available with **cnsreg** but are not shown in the
dialog box:

**mse1** is used only in programs and ado-files that use **cnsreg** to fit models
other than constrained linear regression. **mse1** sets the mean squared
error to 1, thus forcing the variance-covariance matrix of the
estimators to be (X'DX)^-1 (see *Methods and formulas* in **[R] regress**)
and affecting calculated standard errors. Degrees of freedom for t
statistics are calculated as n rather than n-p+c, where p is the
total number of parameters (prior to restrictions and including the
constant) and c is the number of constraints.

**mse1** is not allowed with the **svy** prefix.

**coeflegend**; see **[R] estimation options**.

__Examples__

Setup
**. sysuse auto**

Constrain coefficients of **price** and **weight** to be equal
**. constraint 1 price = weight**

Fit constrained linear regression
**. cnsreg mpg price weight, constraints(1)**

Define more constraints
**. constraint 2 displ = weight**
**. constraint 3 gear_ratio = -foreign**

Fit constrained linear regression, applying all three constraints
**. cnsreg mpg price weight displ gear_ratio foreign length, c(1-3)**

Constrain constant to be zero
**. constraint 99 _cons = 0**

Fit constrained linear regression, applying all four constraints
**. cnsreg mpg price weight displ gear_ratio foreign length, c(1-3,99)**

__Stored results__

**cnsreg** stores the following in **e()**:

Scalars
**e(N)** number of observations
**e(df_m)** model degrees of freedom
**e(df_r)** residual degrees of freedom
**e(F)** F statistic
**e(p)** p-value for model test
**e(rmse)** root mean squared error
**e(ll)** log likelihood
**e(N_clust)** number of clusters
**e(rank)** rank of **e(V)**

Macros
**e(cmd)** **cnsreg**
**e(cmdline)** command as typed
**e(depvar)** name of dependent variable
**e(wtype)** weight type
**e(wexp)** weight expression
**e(title)** title in estimation output
**e(clustvar)** name of cluster variable
**e(vce)** *vcetype* specified in **vce()**
**e(vcetype)** title used to label Std. Err.
**e(properties)** **b V**
**e(predict)** program used to implement **predict**
**e(marginsok)** predictions allowed by **margins**
**e(asbalanced)** factor variables **fvset** as **asbalanced**
**e(asobserved)** factor variables **fvset** as **asobserved**

Matrices
**e(b)** coefficient vector
**e(Cns)** constraints matrix
**e(V)** variance-covariance matrix of the estimators
**e(V_modelbased)** model-based variance

Functions
**e(sample)** marks estimation sample