How do I store a LONG list of names in a macro in Stata?

3.8k views Asked by At

I need to store a very long list of variable names in Stata and after something like 250 characters, no more characters can be stored in a local or global macro. Currently, I'm using many different globals to store the names of the many regressors that I am using but I would much prefer to keep them all in one.

EDIT: The question has been perfectly answered by Maarten below but I would just add the code I was using for precision.

local RHSVARS = "var1 var2 var3 var4  var5 var6 var7 var8 var9 var10 var11 var12 var13 var14 var15 var16 var17 var18 var19"

does not work but

local RHSVARS "var1 var2 var3 var4  var5 var6 var7 var8 var9 var10 var11 var12 var13 var14 var15 var16 var17 var18 var19"

does.

1

There are 1 answers

1
Maarten Buis On BEST ANSWER

This issue is largely solved in Stata 13, so I guess you have an older version.

You can still do so in older versions by just leaving out the equal sign, which you can see in the example below (it ran in Stata 12, in Stata 13 both macros are not truncated). This is discussed in the following article: Nicholas J. Cox (2008) "Stata tip 70: Beware the evaluating equal sign" The Stata Journal, 8(4): 586-587. It is now freely available here: http://www.stata-journal.com/article.html?article=pr0045

. // create local a with an equal sign
. local a = "`c(alpha)' `c(ALPHA)' `c(alpha)' `c(ALPHA)' `c(alpha)' `c(ALPHA)'"

. // create local b by leaving the equal sign out
. local b   "`c(alpha)' `c(ALPHA)' `c(alpha)' `c(ALPHA)' `c(alpha)' `c(ALPHA)'"

.
. // local macro a gets truncated
. di `: length local a'
245

. di "`a'"
a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X
>  Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T
> U V W X Y Z a b c d e f g h i j k l m n o p q r s

.
. // local macro b does not get truncated
. di `: length local b'
311

. di "`b'"
a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X
>  Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T
> U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q
>  R S T U V W X Y Z