Dear Statalist:
I recently decided I wanted to estimate a regression model with an interval constraint, one that is very similar to example #1 here: https://www.stata.com/support/faqs/s...l-constraints/
The idea is that I want to ensure that one variable has a positive coefficient, since all available theory says that the relationship between it (let's call it Variable A) and y is direct.
According to the code on the Stata FAQ, this code is what will do the trick:
This is great. Unfortunately, I have a *lot* of dummy variables and interactions in this model. I only need to set one variable to be positive. Do I have to write out every coefficient like {b}*turn or is there a way to use the factor variable i. notation and the interaction # notation while also setting the constraint for the other (linear) variable A?
Thanks for your help in advance.
edit to above: I should add: What I really wanted to do was to use cnsreg, but it looks like the constraints only work if I want to set variable A to a specific value. I would have liked to do something like this.
But I got a the following error message:
And I don't know what that error is but I'm pretty sure I don't trust it.
Best,
Jonathan
I recently decided I wanted to estimate a regression model with an interval constraint, one that is very similar to example #1 here: https://www.stata.com/support/faqs/s...l-constraints/
The idea is that I want to ensure that one variable has a positive coefficient, since all available theory says that the relationship between it (let's call it Variable A) and y is direct.
According to the code on the Stata FAQ, this code is what will do the trick:
Code:
nl (mpg2 = exp({lna})*price + {b}*turn + {c}), nolog // expressing A as an exponential [lna=ln(a)] and then recovering the parameter [a = exp(lna)] will force it to be positive
nl, coeflegend // this is to find out what Stata is calling lna by looking in the Legend column
nlcom a: exp(_b[lna:_cons]) // this exponentiates the coefficient and returns it
Thanks for your help in advance.
edit to above: I should add: What I really wanted to do was to use cnsreg, but it looks like the constraints only work if I want to set variable A to a specific value. I would have liked to do something like this.
Code:
sysuse auto constraint 1 price>0 cnsreg mpg price c.weight##i.rep78, constraint(1)
But I got a the following error message:
(note: constraint number 1 caused error r(111))
Best,
Jonathan

Comment