Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: operations on macro elements
From
Maarten Buis <[email protected]>
To
[email protected]
Subject
Re: st: operations on macro elements
Date
Wed, 16 May 2012 15:21:49 +0200
On Wed, May 16, 2012 at 2:41 PM, Abhimanyu Arora wrote:
> I have a macro say, x containing the string "a b c"
> I would like to have a macro y such that y contains the string "a_1
> b_1 c_1" ? Is there a simple way using sort of extended functions?
*--------------- begin example ---------------
local x "a b c"
// make sure there is only one space between elements
local x : list retokenize x
// replace "space" by "_1 space"
local y : subinstr local x " " "_1 ", all
// add _1 for the final element
local y "`y'_1"
// see the result
di "`y'"
*---------------- end example ----------------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )
Hope this helps,
Maarten
--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany
http://www.maartenbuis.nl
--------------------------
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/