Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# Re: st: How to use elements of a matrix as constraints in cnsreg

 From Nick Cox <[email protected]> To [email protected] Subject Re: st: How to use elements of a matrix as constraints in cnsreg Date Thu, 11 Aug 2011 18:42:44 +0100

```At a guess, you must evaluate the elements of D, not just refer to
them. Something like

constraint 1 llonepenhx = `= D[1,1]'
constraint 2 lIMD2007 =  `= D[2,1]'
cnsreg yvar x1var x2var llonepenhx  lIMD2007, constraints(1-2)

should mean that -constraint- and thus -cnsreg- just see the evaluated
expressions.

Warning: speculative code; completely untested.

Nick

On Thu, Aug 11, 2011 at 5:53 PM, Steve Martin <[email protected]> wrote:

> I am using Stata 11.  I have a matrix D
>
> . matrix list D
>
> D[2,1]
>                random
> llonepenhx  -.43352401
>  lIMD2007  -.19335928
>
> I want to estimate a constrained regression where the values of certain
> elements of the matrix D serve as constraints in a regression.  In
> particular, I would like to constrain the coefficient on llonepenhx to be
> equal to -0.43352401 and the coefficient on lIMD2007 to be -0.19335928.
>
> Trying
>
> constraint 1 llonepenhx=D[1,1]
> constraint 2 lIMD2007=D[2,1]
> cnsreg yvar x1var x2var llonepenhx  lIMD2007, constraints(1-2)
>
> results in
>
> (note: constraint number 1 caused error r(131))
> (note: constraint number 2 caused error r(131))
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```