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

Re: st: RE: setting global in a loop


From   n j cox <n.j.cox@durham.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: setting global in a loop
Date   Tue, 15 Feb 2005 16:34:38 +0000

My comment was clearly a pontification ex cathedra on code style based
on your example.

But even in this circumstance using -char()- would still not be mandatory. A mix of numbers and other text would be fine.

foreach i in 3 4 5 aberdeen kirkcaldy inverkeithing pitlochry {
global `i'indvars "pid `i'hid"
}

would be fine.

>>> Ada Ma <pec187@abdn.ac.uk>

Thanks Nick for his opinion about using the letters in place of numbers - I'm sort of forced into using the char() function because some data files refer to the waves by number and others by letter. I share the data files with a few others so I dare not change their names to fit my purposes.

Nick Cox wrote:

Taking another look at the code, an alternative is
foreach i in c d e f { global `i'indvars "pid `i'hid" }
The point is mostly one of maintenance.
I wouldn't trust myself to remember that char(99) is "c" for more than a few minutes.
More to the point, on revisiting the code
later a programmer (even the original programmer) who shared this failure of memory would have to work that out afresh. Using the letters directly is more transparent.

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