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]
Re: Rép. : Re: st: Inequality constraints in cnsreg
From
Steven Samuels <[email protected]>
To
[email protected]
Subject
Re: Rép. : Re: st: Inequality constraints in cnsreg
Date
Fri, 5 Nov 2010 17:59:02 -0400
/*
Well, the second version was also incorrect. here's a version that
_presumably_ is, but -nl-- doesn't converge (b1 - b2 is very close to
zero). I thought that I had learned addition and subtraction at a
younger age, but maybe not..
Steve
[email protected]
Your equation is:
y = b0 + b1 x1 + b2 x2 =
= b0 + (b1 - b2) x1 + + b2 (x2 +x1)
If b1 - b2 = exp(c) where c = log(b1 - b2), then b1 - b2>0
Let z = x2 + x1
Then fit the *non-linear* equation
y = exp(c)*x1 + b2 Z
*/
***********CODE BEGINS******
sysuse auto, clear
keep if rep78 !=.
rename rep78 x1
rename foreign x2
rename mpg y
gen z = x2 + x1
reg y x1 x2 //constraint not met
nl (y = {alpha} + exp({c})*x1 + {b2}*z) //get constant & b2
nlcom b1: log(_b[c:_cons]) + _b[b2:_cons] // get b1
matrix b1x =r(b)
gen b1hat = el(b1x,1,1)
/* Get new prediction: no longer OLS */
gen yhatnew = _b[_cons] + b1hat* x1 + _b[b2:_cons]*x2
/* recompute Root MSE */
gen resid = y - yhatnew
gen resid2 = (y - yhatnew)^2
total resid2
local rmse = sqrt(r(b)/e(df_r))
di `rmse' //compare to original Root MSE
*********CODE ENDS***********
---
I've just outlined a solution, Herve. The rest is up to you.
Steve
Steven J. Samuels
[email protected]
18 Cantine's Island
Saugerties NY 12477
USA
Voice: 845-246-0774
Fax: 206-202-4783
On Nov 5, 2010, at 4:38 PM, Herve STOLOWY wrote:
Dear Steven:
Thank you for your reply.
I apologize because I have given first a simplified version of my model.
In other thread, I gave the full model.
Best regards
Hervé
Steven Samuels 05/11/10 21:36 >>>
---
--
Herve, I don't find the FAQ all that enlightening either. Here is a
solution to a reduced problem:
Your equation is:
y = b0 + b1 x1 + b2 x2 =
= (b1 - b2) x1 + + b2( x1 - x2)
If b1 - b2>0 then b1 - b2 = exp(c) for some number c
Let z = x2 - x1
Then fit the *non-linear* equation
y = exp(c)*x1 + b2 Z
and solve for b2
***********CODE BEGINS******
sysuse auto, clear
keep if rep78 !=.
rename rep78 x1
rename foreign x2
rename mpg y
gen z = x1 - x2
reg y x1 x2 //constraint not met
nl (y = {alpha} + exp({c})*x1 + {b2}*z) //get constant & b2
nlcom b1: log(_b[c:_cons]) +_b[b2:_cons] // get b1
*********CODE ENDS***********
Steve
Steven J. Samuels
[email protected]
18 Cantine's Island
Saugerties NY 12477
USA
Voice: 845-246-0774
Fax: 206-202-4783
On Nov 5, 2010, at 2:07 PM, Herve STOLOWY wrote:
Dear Statalisters:
I am using Stata 11.1
I would like to use cnsreg to create the following constaints:
Y X1 X2 X3 X4
constriant 1 X2 > X1
constraint 2 X4 > X3
I have read the threads which existed a few years ago and a recent one
on the topic of inequality constraints
(http://www.stata.com/statalist/archive/2010-04/msg01437.html).
I have also read the answer from Marteen Buis and his suggested solution
(http://www.stata.com/support/faqs/stat/intconst.html).
I do not understand very well the suggested solution and I am not
trained in programming.
Consequently, my question is the following: is there a "not too complex"
solution to get the constraints I need?
Best regards
Hervé Stolowy
*
* 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/
*
* 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/
*
* 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/
*
* 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/