Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
Meg22 <[email protected]>:
The FAQ http://www.stata.com/support/faqs/stat/intconst.html
advises that "The examples in this tutorial are for illustration
purposes only. If you need to fit a linear regression with interval
constraints, use the Stata command nl. " but I don't see an example of how
to do constrained regression using -nl- linked from there. Here is a
simple example:
sysuse auto, clear
reg price mpg turn, nohe
nl (price={b1}*mpg+{b2}*turn+{_cons}), nolog
* constrain coef on mpg to be positive:
nl (price=exp({b1})*mpg+{b2}*turn+{_cons}), nolog
nlcom exp(_b[/b1])
Note that when you constrain the coef on mpg to be nonnegative, the
estimated coef exp(b1) gets driven right to zero as b1 seeks negative
infinity and you wind up with a model essentially equivalent to:
reg price turn
If you want to impose all coefs are nonnegative and sum to one, try:
sysuse auto, clear
g gpm=1/mpg
g wt=weight/1000
g l=length/1000
g tn=turn/1000
reg gpm wt l tn, nohe
* constrained to be positive:
nl (gpm=exp({b1})*wt+exp({b2})*l+exp({b3})*tn+{_cons}), nolog
nlcom (exp(_b[/b1])) (exp(_b[/b2])) (exp(_b[/b3])), post
* constrained to be positive and sum to one:
nl (gpm=exp({b1})*wt+exp({b2})*l+(1-exp({b1})-exp({b2}))*tn+{_cons}) nlcom
(exp(_b[/b1])) (exp(_b[/b2])) (1-exp(_b[/b1])-exp(_b[/b2])), post
But imposing such assumptions tends to result in very implausible
models, unless the unconstrained coefs are very close to satisfying your
constraints. See also p.1188 of [R] nl.
On Fri, Jun 3, 2011 at 2:03 AM, Nick Cox <[email protected]> wrote:
> This is an FAQ. See
>
> How do I fit a regression with interval constraints in Stata?
> Isabel Cañette, StataCorp
> October 2006; updated July 2008; minor revisions April 2011
> http://www.stata.com/support/faqs/stat/intconst.html
>
> Nick
>
> On Fri, Jun 3, 2011 at 12:24 AM, Meg22 <[email protected]> wrote:
>
>> I need to do a constrained regression in stata-I need all the beta
coefficents to be positive and sum to 1.
>>
>> I have 11 independent variables so my regression is:
>> reg Rrf bills it lt cor lcvalue lcgrowth medcap smallcap noncanbonds us
jap
>> if fundno ==`i'
>>
>> I need all the betas to be positive, sum to 1 and there to be a constant.
>>
>> I got the summing to 1 bit I think:
>> constraint define 1 bills + it + lt + cor + lcvalue + lcgrowth + medcap
+ smallcap + noncanbonds + us + jap = 1
>> cnsreg Rrf bills it lt cor lcvalue lcgrowth medcap smallcap
noncanbonds us
>> jap, constraint(1)
>>
*
* 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/