----- Original Message -----
From: "Savych, Bogdan" <[email protected]>
To: <[email protected]>
Sent: Tuesday, June 24, 2003 5:03 PM
Subject: st: loop that refers to global
> I want to write a do-file that uses loops to refer to some global macros.
> Global macros define different variables that I want to use in different
> regressions. However, when I run program I receive an error. Example of
> the do-file is goes like this:
>
> version 7
> global cov1="var3"
> global cov2="var3 var4"
> global cov3="var3 var4 var5"
>
> local i=1
> while `i'<=3 {
> logistic y var1 var2 $cov`i'
> local i=`i'+1
> }
>
>
> After I run this do file it gives an error:
>
> 1 invalid name
> r(198);
>
> Does this mean that I can not use loops that refer to macros? What should
I
> change for this to run? Any advise would be appreciated. Option to write
> explicitly each regression does sound quite attractive.
>
> Thanks,
>
> Bogdan Savych
> Graduate Fellow
> RAND Graduate School
How about with local macros? This works:
local cov1 "price"
local cov2 "price weight"
forval i = 1/2 {
logit fore length `cov`i''
}
Hope this helps,
Scott
*
* 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/