Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: tempvar in debugging
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: tempvar in debugging
Date
Fri, 7 Jan 2011 08:58:39 +0000
First, a detail: it's better style to use a -tempname- when you want
to name a matrix.
All that's biting you here -- and it's an important "all" -- is that
temporary names are local macros and so are invisible outside the
program (or more generally place) in which they are defined. That's
what "local" means.
As you want your matrix to be visible outside -test-, you need to give
it a permanent name, or to save it at the end of your program.
In this case, I can't see any point to writing the program. On the
other hand, if it's just a minimal example concocted to make your
point, that's fine.
Nick
On Fri, Jan 7, 2011 at 4:07 AM, Wincent <[email protected]> wrote:
> Dear all, here is the situation I ran into:
>
> *** first case
> capture program drop test
> program define test
> tempvar x
> matrix `x'=(1,2\3,4)
> pause examine matrix `x'
> end
>
> pause on
> test
> pause: examine matrix __000000
> -> . matrix dir
> __000000[2,2]
> -> . matrix list `x'
> matrix name required
> r(100);
> -> . matrix list __000000
> __000000[2,2]
> c1 c2
> r1 1 2
> r2 3 4
> -> . end
> execution resumes...
>
> ** second case
> tempvar x
> matrix `x'=(1,2\3,4)
> matrix list `x'
>
> In the first case, I can't use macro name to inspect the matrix, but
> the second case I can.
> I wonder why it throws an error in the first case, and is there any
> way to inspect the matrix instead of using the actual tempvar
> __000000?
>
*
* 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/