# Re: st: RE: simple problem with local macro

 From "David Ward" To statalist@hsphsun2.harvard.edu Subject Re: st: RE: simple problem with local macro Date Thu, 10 May 2007 11:36:44 -0400

```On 5/10/07, Maarten Buis <M.Buis@fsw.vu.nl> wrote:
```
```replace the line:

local a  `i'+9

with :

local a = `i'+9
```
```Gee, so simple!
Thanks,
David Ward

```
```-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of David Ward
Sent: donderdag 10 mei 2007 17:26
To: statalist@hsphsun2.harvard.edu
Subject: st: simple problem with local macro

Dear Statalisters,

I have a simple question about a local macro, as illustrated in this example.
***************************************
. clear

. set obs 3
obs was 0, now 3

. gen x = _n*10

. gen str10 a_rang=""
(3 missing values generated)

. forvalues i=10(10)30 {
2.         local a  `i'+9
3.         disp `a'
4.         replace a_rang="`i'" + "-" + "`a'" if x==`i'
5. }
19
29
39

. list, clean noobs

x    a_rang
10   10-10+9
20   20-20+9
30   30-30+9
***************************************************************

I want the a_rang variable to be "10-19", "20-29", and so on, as it
appears it would be when I -display- it.  Even with my rudimentary
knowledge of local macros, I can get around the problem by, for
example, defining another local macro equal to a.  But it seems there
should be a direct way to accomplish this in the -replace- command
above, to include the numeric value of local macro a rather than the
"`i'+9" string.

Thanks,
David Ward
*
*   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/

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