Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: RE: local variables program


From   "Steichen, Thomas J." <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: RE: local variables program
Date   Mon, 25 Jun 2007 08:53:32 -0400

How about this.... (edited lines commented out; some lines reordered)
 
global maxRMSE=999999999999999999
sum  avgunitprice if id==5, detail
global min=r(p5)
global max=r(p95)
*forval i= 1 2 100 {
forval i = 1(2)100 {
  scalar j = $min + `i' * ($max - $min) / 100 
*  gen belowprice=avgunitprice*(avgunitprice<`j') 
  gen below = avgunitprice < `j'
  gen belowprice = avgunitprice * below 
*  gen aboveprice=avgunitprice*(avgunitprice>=`j')
  gen above = avgunitprice >= `j'
  gen aboveprice = avgunitprice * above
  qui reg lunit below belowprice above aboveprice if id==5, nocons
  if e(rmse) < $maxRMSE {
*    local $maxRMSE=e(rmse)
    global maxRMSE = e(rmse)
    reg lunit below belowprice above aboveprice		  
  }
* cap drop below belowprice aboveprice above j
  cap drop below belowprice aboveprice above
}
di $maxRMSE


-----------------------------------
Thomas J. Steichen
[email protected]
-----------------------------------
 
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nachbar, Dirk
Sent: Monday, June 25, 2007 6:21 AM
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/

-----------------------------------------
CONFIDENTIALITY NOTE: This e-mail message, including any
attachment(s), contains information that may be confidential,
protected by the attorney-client or other legal privileges, and/or
proprietary non-public information. If you are not an intended
recipient of this message or an authorized assistant to an intended
recipient, please notify the sender by replying to this message and
then delete it from your system. Use, dissemination, distribution,
or reproduction of this message and/or any of its attachments (if
any) by unintended recipients is not authorized and may be
unlawful.


*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index