Thanks to all. The programs works now. In case you are interested, see
below. This is basically a threshold demand model.
global minRMSE=999999999999999999
sum avgunitprice if id==8, detail
global min=r(p5)
global max=r(p95)
forval i = 1(2)100 {
scalar j = $min + `i' * ($max - $min) / 100
cap drop below* above*
gen below = avgunitprice < j
gen belowprice = avgunitprice * below
gen above = avgunitprice >= j
gen aboveprice = avgunitprice * above
qui reg lunit below belowprice above aboveprice if id==8, nocons
if e(rmse) < $minRMSE {
global minRMSE = e(rmse)
di j
reg lunit below belowprice above aboveprice if id==8, nocons
}
}
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/