Statalist


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

st: re: saved local macro


From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: re: saved local macro
Date   Fri, 31 Oct 2008 08:30:44 -0400

< >
Martin is correct in suggesting that you should return a scalar. But if you work with macros, note that macros are _always_ strings. They may contain nothing but numbers, and Stata is smart enough to evaluate them as numbers in context:

program cu7, rclass
local numd 1
return local numd =`numd'
end

cu7
local foo = `r(numd)' + 1
di "`foo'"

If you display r(numd), you get "1", which is the value to which r(numd) is aliased. If you speak of it as `r(numd)', you are explicitly directing Stata to replace r(numd) in the -local- command with its value, and then execute the command. That works fine.


Kit Baum, Boston College Economics and DIW Berlin
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html


*
*   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/



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