Statalist The Stata Listserver


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

st: Re: Using local variables in the name of a global variable


From   "Michael Blasnik" <michael.blasnik@verizon.net>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Re: Using local variables in the name of a global variable
Date   Fri, 17 Mar 2006 10:25:50 -0500

You need to reference the global macro name using brackets to make it clear to Stata what you want:

di "${gooddaysY`y'M`m'}"

Michael Blasnik

----- Original Message ----- "Danielle H. Ferry" <dferry@nber.org> wrote:


I want to define a global variable whose name contains 2 local variables (b/c
I am creating it w/in nested loops over year & month):

forval y = 1980(1)2006 {
forval m = 1(1)12 {
global gooddaysY`y'M`m' = "stuff"
di "$gooddaysY`y'M`m'"
}
}

Suppose we are in the y = 1980 & m = 1 loop. Then the result of the -display-
is: 1980M1. I am guessing this has something to do w/ the quotes. But I don't
know how to fix it. Any ideas?

Thanks,
Danielle Ferry
*
*   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–2020 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index