Statalist The Stata Listserver


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

st: RE: simple problem with local macro


From   "Maarten Buis" <M.Buis@fsw.vu.nl>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: simple problem with local macro
Date   Thu, 10 May 2007 17:29:28 +0200

replace the line:

local a  `i'+9

with :

local a = `i'+9


-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology 
Vrije Universiteit Amsterdam 
Boelelaan 1081 
1081 HV Amsterdam 
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434 

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------

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

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