Statalist The Stata Listserver


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

Re: st: RE: Foreach Problem


From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   Re: st: RE: Foreach Problem
Date   Mon, 30 Oct 2006 19:02:22 -0500

Your misunderstanding comes from the fact that display supports expressions and will evaluate them and display them. -rename- does not evaluate string expressions, so you need to evaluate it when assigning it to the local macro.

Michael Blasnik

----- Original Message ----- From: "Raphael Fraser" <[email protected]>
To: <[email protected]>
Sent: Monday, October 30, 2006 5:53 PM
Subject: Re: st: RE: Foreach Problem



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:

. local newname substr("haem_id", 6, .)
. di `newname'
id

However, typing the foll. does not work:

rename haem_id `newname'
( not allowed

trace on
foreach var of varlist haem_id - haem_nbc {
- local newname `=substr(`var', 6, .)'
type mismatch
= local newname
- rename `var' `newname'
= rename haem_id
varname required
 }
r(100);
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index