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

st: Re: Iterative regression runs


From   "Jelmer Ypma" <[email protected]>
To   <[email protected]>
Subject   st: Re: Iterative regression runs
Date   Wed, 22 Dec 2004 00:40:07 -0800

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."
This error message means that you're trying to generate a variable which already exists. Try
-gen x = 1
and then
-gen x = 2
you get the same error message.

There are (at least) two things you can do, depending on whether you want to look at the dummy variable later.

Generate different dummies:
forvalues i=1(0.5)5 {
gen dummy`i' = (spread>`i')
reg y x dummy`i'
...
}

or make it a temporary variable
forvalues i=1(0.5)5 {
tempvar dummy
gen `dummy' = (spread>`i')
reg y x `dummy'
...
}

Don't forget the quotes around `dummy' in that case.

Good luck!

Jelmer


--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.296 / Virus Database: 265.6.2 - Release Date: 12/20/2004


--------------------

This email message is for the sole use of the intended recipient(s) and
may contain privileged information. Any unauthorized review, use,
disclosure or distribution is prohibited. If you are not the intended
recipient, please contact the sender by reply email and destroy all copies
of the original message.

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