Stata 15 help for makecns

[P] makecns -- Constrained estimation


Build constraints

makecns [clist|matname] [, options]

Create constraint matrix

matcproc T a C

where clist is a list of constraint numbers, separated by commas or dashes; matname is an existing matrix representing the constraints and must have one more column than the e(b) and e(V) matrices.

T, a, and C are names of new or existing matrices.

options Description ------------------------------------------------------------------------- nocnsnotes do not display notes when constraints are dropped displaycns display the system-stored constraint matrix r return the accepted constraints in r(); this option overrides displaycns -------------------------------------------------------------------------


makecns is a programmer's command that facilitates adding constraints to estimation commands.

makecns will create a constraint matrix and displays a note for each constraint that is dropped because of an error. The constraint matrix is stored in e(Cns).

matcproc returns matrices helpful for performing constrained estimation, including the constraint matrix.

If your interest is simply in using constraints in a command that supports constrained estimation, see [R] constraint.


nocnsnotes prevents notes from being displayed when constraints are dropped.

displaycns displays the system-stored constraint matrix in readable form.

r returns the accepted constraints in r(). This option overrides displaycns.


Here is an outline for programs to perform constrained estimation using makecns:

program myest, eclass properties(...) version 15.1 if replay() { // replay the results if ("`e(cmd)'" != "myest") error 301 syntax [, Level(cilevel) ] makecns , displaycns } else { // fit the model syntax whatever [, /// whatever /// Constraints(string) /// Level(cilevel) /// ] // any other parsing of the user's estimate request tempname b V C T a bc Vc local p=number of parameters // define the model (set the row and column // names) in `b' if "`constraints'" != "" { matrix `V' = `b''*`b' ereturn post `b' `V' // a dummy solution makecns `constraints', display matcproc `T' `a' `C' // obtain solution in `bc' and `Vc' matrix `b' = `bc'*`T'' + `a' // note prime matrix `V' = `T'*`Vc'*`T'' // note prime ereturn post `b' `V' `C', options } else { // obtain standard solution in `b' and `V' ereturn post `b' `V', options } // store whatever else you want in e() ereturn local cmd "myest" } // output any header above the coefficient table ereturn display, level(`level') end

Stored results

makecns stores the following in r():

Scalars r(k_autoCns) number of base, empty, and omitted constraints

Macro r(clist) constraints used (numlist or matrix name)

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index