Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: Creating a macro of variable names

From   "Michael Blasnik" <>
To   <>
Subject   st: Re: Creating a macro of variable names
Date   Fri, 13 May 2005 12:39:40 -0400

unab vmacro: abc*
global varmacro "`vmacro'"

note: do not use the equal sign when creating string macros, it can truncate the result

Michael Blasnik

----- Original Message ----- From: "David Hadley" <>
To: <>
Sent: Friday, May 13, 2005 12:31 PM
Subject: st: Creating a macro of variable names

Hi All,

I'm trying to create a global macro containing certain variable names - but I'm having trouble appending/concatenating macros (as opposed to redefining the macro).

Assuming I have some variables called abc1, abc2, and abc3, here's my do-file so far:

foreach var of varlist abc* {
global varmacro = `"`$varmacro' `var'"'

This currently only stores (in varmacro) the last abc* variable ("abc3"), whereas I want it to produce a macro of "abc1 abc2 abc3".

I would have though this command could be done in one line rather than using a do-file, but would appreciate any method that works.

Thanks in advance,

*   For searches and help try:

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