Statalist The Stata Listserver


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

st: simple problem with local macro


From   "David Ward" <[email protected]>
To   [email protected]
Subject   st: simple problem with local macro
Date   Thu, 10 May 2007 11:26:21 -0400

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
(1 real change made)
29
(1 real change made)
39
(1 real change made)

. 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/



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