Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Re: Problem with tempvar __000000


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Re: Problem with tempvar __000000
Date   Mon, 21 Jun 2004 09:29:51 +0100

I concur with Tom's analysis. Like him, 
I can't reproduce the "already defined" message. 

Note two further details. 

The fact that a temporary variable does not persist 
beyond the end of a do file is explicit within [P] 
macro but may come as a surprise.  

The particular temporary variable name __000000 can only 
I think be reproduced if you have not created 
temporary variables earlier in the same session. More 
generally, Stata avoids names previously 
used in a session even if variables with those names 
no longer exist. Presumably always using a new name 
is the easiest and safest general solution. 

A little experiment you can try is 

forval i = 1/10 { 
	tempvar foo 
	gen `foo' = 1 
	di "`foo'" 
	drop `foo' 
} 

This incidentally illustrates one use of tempvars 
within a main program, to elucidate some programming 
puzzle without writing a named program. 

Nick 
n.j.cox@durham.ac.uk 

Tom Steichen
 
> For the situation you describe below, retention of the temp 
> variable in the
> saved dataset is the expected behavior.
> 
> Temp variables are deleted automatically only when their 
> creating program
> (or do file) ends. Thus they remain in existence until dropped or the
> program (or do file) that created them ends.  It follows that 
> if you create
> a temp variable in the "main" program level of Stata, the 
> temp variable
> remains in existence until either dropped or you exit from 
> Stata. If you do
> a -save- without specifying which variables, all variables, 
> including temp
> variables, get saved.
> 
> I tried your example, exactly as you show below but on Stata SE (not
> Intercooled), born the same date you show, and I do not get any error
> message even though __000000 exists.  Thus the entanglement 
> of Graph with
> the temp variable may be an Intercooled problem.

Renzo Comolli
 
> > A variable created by -tempvar- is hanging around inside the saved
> dataset.
> > Its name is __000000
> > Is that normal behavior? I had never noticed this behavior 
> before, but maybe I am just confused.
> >
> > See the (reproducible) code below, taken from my results window.
> > The case presented here is benign, but soemtimes malign cases occur:
> > A. the code gives an error message and still performs the 
> operation, as in
> > the exaple of -twoway- here below
> > B. I believe that at least in one case, it actually broke 
> the code. It was
> > in a -reshape long-. (I can't be sure though, because I was 
> tearing a huge
> > file apart to figure out where the problem was coming from).
> >
> > If, after the code below, you actually issue once again
> > . use debugauto, clear
> > then variable __000000 appears in the variable window.
> >
> > Any clarification? Is it a bug? I am missing something?
> >
> > Best Regards,
> > Renzo Comolli
> >
> >
> >
> > Here is the code to reproduce (most) of the behavior described.
> >
> > . about
> > Intercooled Stata 8.2 for Windows
> > Born 18 May 2004
> >
> > . sysuse auto, clear
> > (1978 Automobile Data)
> >
> > . tempvar num_miss
> >
> > . gen `num_miss'=0
> >
> > . save debugauto, replace
> > file debugauto.dta saved
> >
> > .
> > . use debugauto, clear
> > (1978 Automobile Data)
> >
> > . describe __000000
> >
> >               storage  display     value
> > variable name   type   format      label      variable label
> > 
> --------------------------------------------------------------
> ------------
> --
> > ---
> > __000000        float  %9.0g
> >
> > . tab __000000, mi
> >
> >    __000000 |      Freq.     Percent        Cum.
> > ------------+-----------------------------------
> >           0 |         74      100.00      100.00
> > ------------+-----------------------------------
> >       Total |         74      100.00
> >
> > . twoway (lfit  price  mpg) (scatter  price mpg), by( foreign)
> > __000000 already defined
> >
> > * but the graph still appears correctly

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index