Statalist The Stata Listserver


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

RE: st: local variable within a global macro?


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: local variable within a global macro?
Date   Tue, 29 Aug 2006 14:23:19 +0100

No. This is definitely not a solution. It 
will look for a _local_ with name 

$X`p'  

Quite apart from other details, Nishant's 
code calls for a global here. 

Nick 
n.j.cox@durham.ac.uk 

Vimalanand S. Prabhu
 
> Try changing to `$X`p''
 
Nishant Dass 
 
> > I have a small (or so it seems) problem with a loop (shown
> > below).  
> > 
> > I start by generating a few global macros:
> > global X2 "age2 weight2 height2"
> > global X3 "age3 weight3 height3"
> > ...
> > global X11 "age11 weight11 height11"
> > 
> > Then I try to run the following set of regressions using a
> > loop:
> > forvalues n = 1/10 {
> > 	local p = `n' + 1
> > 	reg y`n' $X`p'
> > }
> > 
> > However, this isn't executed due to an error that says "2
> > invalid name" (i.e., it's referring to some problem in the
> > way I have used `p' in $X`p'.)

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index