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

# st: Fitting a linear regression with interval (inequality) constraints using nl

 From "Lieke Boonen (SiRM)" To "statalist@hsphsun2.harvard.edu" Subject st: Fitting a linear regression with interval (inequality) constraints using nl Date Tue, 14 Feb 2012 18:56:07 +0100

```Dear users
The problem we face is that we have to estimate a restricted OLS model for = which all betas have to be positive. We use the nl command (non lineair) in=  which we estimate the exp(beta) to make sure the beta is positive. However=  it takes a long time to converge and we want to know if there is an easier=  solution.

In SAS you use the proc nlin command in which you state bounds for the beta=  to be larger than 0. You thus specify a normal lineair regression and add = the bound that the beta is larger than 0. In Stata we tried the constraint = regression (cnsreg) but we cannot create a constraint wich beta>0.

Is there something we are missing or is the code we have written below the = only code that Works in such a situation?

We have written the following code: (76 betas)

nl (gemiddelde_kosten_gewogen =3D exp({lnb1})*lgnw1 + exp({lnb2})*lgnw2 + e=
xp({lnb3})*lgnw3 + exp({lnb4})*lgnw4 + exp({lnb5})*lgnw5 ///
+ exp({lnb6})*lgnw6 + exp({lnb7})*lgnw7 + exp({lnb8})*lgnw8 + e=
xp({lnb9})*lgnw9 + exp({lnb10})*lgnw10 ///
+ exp({lnb11})*lgnw11 + exp(=
{lnb12})*lgnw12 + exp({lnb13})*lgnw13 + exp({lnb14})*lgnw14 + exp({lnb15})*=
lgnw15 ///
+ exp({lnb16})*lgnw16 + exp({lnb17})*lgnw17 + exp({lnb18})*lgnw=
18 + exp({lnb19})*lgnw19 + exp({lnb20})*lgnw20 ///
+ exp({lnb21})*lgnw21 + exp(=
{lnb22})*lgnw22 + exp({lnb23})*lgnw23 + exp({lnb24})*lgnw24 + exp({lnb25})*=
lgnw25 ///
+ exp({lnb26})*lgnw26 + exp({lnb27})*lgnw27 + exp({lnb28})*lgnw=
28 + exp({lnb29})*lgnw29 + exp({lnb30})*lgnw30 ///
+ exp({lnb31})*ape1 + exp({l=
nb32})*ape2 + exp({lnb33})*ape3 + exp({lnb34})*ape4 + exp({lnb35})*ape5 ///
+ exp({lnb36})*ape6 + exp({l=
nb37})*ape7 + exp({lnb38})*ape8 + exp({lnb39})*ape9 + exp({lnb40})*ape10 //= /
+ exp({lnb41})*drempel_laag_= niet + exp({lnb42})*drempel_laag + exp({lnb43})*drempel_hoog_niet + exp({ln=
b44})* drempel_hoog ///
+ exp({lnb45})*mph + exp({ln= b46})*eph + exp({lnb47}) * avi11 + exp({lnb48})*avi21 + exp({lnb49})*avi31 =
+exp({lnb50})* avi41 ///
+ exp({lnb51}) * avi12 +exp(=
{lnb52})*avi22 + exp({lnb53})*avi32 +exp({lnb54})* avi42 ///
+ exp({lnb55}) * avi13 +exp(=
{lnb56})*avi23 + exp({lnb57})*avi33 +exp({lnb58})* avi43 ///
+ exp({lnb59}) * avi14 + exp=
({lnb60})*avi24 + exp({lnb61})*avi34 +exp({lnb62})* avi44 ///
+ exp({lnb63}) * ses1a + exp= ({lnb64})*ses2a + exp({lnb65}) *ses3a + exp({lnb66})*ses4a + exp({lnb67}) *=  ses1b + exp({lnb68})*ses2b ///
+ exp({lnb69}) *ses3b + exp(= {lnb70})*ses4b + exp({lnb71}) * fkg0 + exp({lnb72}) * fkg1 + exp({lnb73}) *=
fkg2 + exp({lnb74}) * fkg3 ///
+ exp({lnb75}) * fkg4 + exp(=
{lnb76}) * fkg5), noconst

*
*   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/
```