Statalist The Stata Listserver

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

Re: st: RE: Foreach Problem

From   "Michael Blasnik" <>
To   <>
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" <>
To: <>
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'

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
*   For searches and help try:

© Copyright 1996–2021 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index