Statalist The Stata Listserver


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

Re: st: RE: Foreach Problem


From   "Raphael Fraser" <raphael.fraser@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: Foreach Problem
Date   Mon, 30 Oct 2006 19:08:39 -0500

Thanks

set trace on
. foreach var of varlist haem_id - haem_nbc {
 2.         local newname = substr("`var'", 6, .)
 3.         rename `var' `newname'
 4.         }
- foreach var of varlist haem_id - haem_nbc {
- local newname = substr("`var'", 6, .)
= local newname = substr("haem_id", 6, .)
- rename `var' `newname'
= rename haem_id id
- }


On 10/30/06, Austin Nichols <austinnichols@gmail.com> wrote:
foreach var of varlist haem_id - haem_nbc {
         local newname=substr("`var'", 6, .)
         rename `var' `newname'
         }

or

foreach var of varlist haem_id - haem_nbc {
         rename `var' `=substr("`var'", 6, .)'
         }

for that matter.

On 10/30/06, Raphael Fraser <raphael.fraser@gmail.com> wrote:
> Didn't work. From the trace as you said -substr(`var', 6, .)- is not
> being evaluated as I expected. Typing the following in the command
> line works:
*
*   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/

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