Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: How to separate multiple word assignments to a macro

From   Michael Norman Mitchell <>
Subject   Re: st: How to separate multiple word assignments to a macro
Date   Fri, 09 Apr 2010 20:07:46 -0700

Dear Tom

  I wonder if this would do the trick for you...

local TreasRatesDisplay `""5 Yr Treas Rate" "10 Yr Treas Rate" "20 Yr Treas Rate""'

You could extract the three pieces like this...

local a : word 1 of `TreasRatesDisplay'
local b : word 2 of `TreasRatesDisplay'
local c : word 3 of `TreasRatesDisplay'

And then you can display the three pieces like this

. di "The first word is `a'"
The first word is 5 Yr Treas Rate

. di "The second word is `b'"
The second word is 10 Yr Treas Rate

. di "The third word is `c'"
The third word is 20 Yr Treas Rate

The key is using the -compound double quotes- which start with `" and end with "' . These are like super duper quotes that can hold a quoted string, and Stata understand that each quoted pair is a different -word-.

You can even extact the number of words using the "word count" function...

. local wc : word count `TreasRatesDisplay'
. di `wc'

  I hope this is helpful.

Michael N. Mitchell
See the Stata tidbit of the week at...

On 2010-04-09 4.45 PM, Thomas Jacobs wrote:
I am trying to create a macro of readable variable names for later
output in multiple tables.  Thus, the number of variable names will
change.  For example assume I have a case with three values such as

5 Yr Treas Rate, 10 Yr Treas Rate, 20 Yr Treas Rate

which I wish to assign to the macro TreasRatesDisplay

Is there any way to do this and end up with just 3 values in the macro
where each value may have embedded spaces?  Thanks.


Thomas Jacobs
*   For searches and help try:
*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index