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

RE: st: Re: forvalues over firms


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Re: forvalues over firms
Date   Mon, 23 Jun 2003 13:31:33 +0100

Danielle H. Ferry replied to Kit Baum 

> > local rhs
> > * replace with number of firms
> > local nfirm 5
> > forv i=1/`nfirm' {
> > local rhs "`rhs' (xret`i' xmkt`i')"
> > }
> > di "`rhs'"
> > sureg `rhs',corr
> > 
> > Note well the lack of an equal sign in the definition of 
> local rhs.

> Is this so that the local variable <rhs> exists outside of 
> the -forvalue-
> loop?

No, that's not the reason. 

Within the loop the macro defined by 

local rhs "`rhs' (xret`i' xmkt`i')"

can continue to grow to moderate length, 
whereas the macro defined by 

local rhs = "`rhs' (xret`i' xmkt`i')"

can be truncated: the = sign obliges
an evaluation of whatever is to the right of 
here, and there is a length limit of 80 characters 
(244 characters in Stata/SE) on strings to be evaluated. 
See help on -limits-. 

In this case, and many others, no evaluation is 
needed, just substitution of macro 
contents, so the = sign is not necessary. 
And as it can do harm, by truncating the 
string, it should definitely be avoided. 

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

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