see -help forvalues-
-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands
visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434
+31 20 5986715
http://home.fsw.vu.nl/m.buis/
-----------------------------------------
-----Original Message-----
From: [email protected] [mailto:[email protected]]On Behalf Of Nachbar, Dirk
Sent: maandag 25 juni 2007 12:21
To: [email protected]
Subject: st: RE: RE: local variables program
Thanks Maarten
But that still doesn't work properly. I can't really figure it out. See
below for the amended program.
Dirk
global maxRMSE=999999999999999999
sum avgunitprice if id==5, detail
global min=r(p5)
global max=r(p95)
forval i= 1 2 100 {
scalar j=$min+`i'*($max-$min)/100
gen belowprice=avgunitprice*(avgunitprice<`j')
gen below=(avgunitprice<`j')
gen aboveprice=avgunitprice*(avgunitprice>=`j')
gen above=(avgunitprice>=`j')
qui reg lunit below belowprice above aboveprice if id==5, nocons
if e(rmse)<$maxRMSE {
local $maxRMSE=e(rmse)
reg lunit below belowprice above aboveprice
}
cap drop below belowprice aboveprice above j
}
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Maarten Buis
Sent: 25 June 2007 10:59
To: [email protected]
Subject: st: RE: local variables program
--- Nachbar, Dirk
> I want to run some regressions and have problems with the local and
> global variables. I think Stata doesn't like the forval loop. How
should
> I refer to min and max?
>
> local max=999999999999999999
> sum avgunitprice if id==5, detail
> global min=r(p5)
> global max=r(p95)
> forval i= min min+(max-min)/100 to max {
<snip>
Have a look at -help macro- to see how you can refer to locals and
globals. If you want to refer to a global max you type $max, if you
want to refer to a local max you type `max'. Anyhow I would not put
computation inside a -forval- statement, so I would first create a
local with the minimum value and feed that into the -forval-
statement.
Hope this helps,
Maarten
-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands
visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434
+31 20 5986715
http://home.fsw.vu.nl/m.buis/
-----------------------------------------
*
* 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/
*
* 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/
*
* 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/