Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Iterative regression runs


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Iterative regression runs
Date   Tue, 21 Dec 2004 20:41:59 -0000

Yes indeed. Second time around your loop, 
you need -replace-, not -generate-. One 
way to deal with this is to -generate- 
outside the loop, and then -replace- 
within it. 

By the way, don't go 1(0.5)5. That should 
work fine, but if you do this, you will
get burned some time in the future when 
you go 1(0.1)50 or whatever. Sooner or 
later the binary/decimal precision issue 
will catch up with you. 

generate dummy = . 
forval i=2/10 {
 	replace dummy = spread > (0.5 * `i')
 	reg y x dummy
	... 	
}

Nick 
[email protected] 

Hamilton, David
 
> I'm a relatively new Stata user with a simple question. I 
> want to iteratively run a regression that allows a dummy 
> variable to change value (compared to the value of a 
> reference variable called "spread") and append some of the 
> results of each run to a table/matrix.
> 
> This is a simplified version of what I'm trying to do (never 
> mind what it's supposed to mean):
> 
> Forvalues i=1(0.5)5 {
> 	gen dummy = (spread>`i')
> 	reg y x dummy
> 	here I want to append the value of i and the AIC to a 
> (i,2) matrix so I can look at the results later and pick out 
> the value of i that is min(AIC)
> }
> 
> This would seem to be a simple thing, but the loop stops 
> after the first iteration with the message "dummy already defined."

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