Statalist


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

st: AW: converting macros into variables


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: converting macros into variables
Date   Fri, 13 Feb 2009 09:32:24 +0100

<> 


Interpretation is usually facilitated in these cases with the help of -set
trace on-. Make sure you have - set traceexpand on - so you can see what
Stata makes of your -macro-s. Even with Kieran`s improvement of your code,
you would still end up with an empty dataset unless you -set obs- to
whatever seems appropriate for your particular problem.

BTW, in what kind of a situation would one need such a construct?



HTH
Martin

-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Luhang Wang
Gesendet: Freitag, 13. Februar 2009 05:05
An: [email protected]
Betreff: st: converting macros into variables

Hi All,
Does anyone know an easy way of converting macros into variables?
I'm trying something like the following.
local x1=1
local x2=2
local vl "x1 x2"
foreach v of loc vl {
        gen "`v'"=`"`v'"'
}
I end up with error message
"x1 invalid name
r(198);
How to interprete this?
I guess there is better method to achieve the goal. Any hint will be
appreciated.
Thanks.
Luhang
*
*   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/


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