Statalist The Stata Listserver


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

Re: st: a question about tempvar


From   Jian Zhang <[email protected]>
To   [email protected]
Subject   Re: st: a question about tempvar
Date   Mon, 6 Feb 2006 17:36:12 -0800 (PST)

Dear Jean-Benoit and Stata Users,

Thanks.  It really helps.

But I just have one concern.  If we have to add drop `temxxx', what is the point of using command
tempvar?   It seems that we could just use the following commands to do
the same thing:

use file.dta, clear

sort eid
by eid: gen temxxx=_n
drop if temxxx!=1

drop temxxx

sort eid

save file1.dta, replace

It seems to me that this way is simpler than using command tempvar since
this do file has one line less than using command tempvar.  Any reasons or
motivations for using tempvar rather than creating a actual new variable?

Thanks.

Jian Zhang





On Tue, 7 Feb 2006, Jean-Benoit Hardouin wrote:
> Dear Jian,
> __000000 corresponds to the name of the temporary variable `tempxxx'. This "temporary" variable is not dropped in the saved file (only at the end of your command). The solution is to add
>
> drop `tempxxx'
>
> before the line
>
> save file1.dta, replace
>
> Jean-Benoit
>
>
>
> Jian Zhang a �crit :
>
> >Dear Stata Users,
> >
> >Have you run into the following problem when using command tempvar?  I can
> >not fix the problem.  Hope that you can help me out.
> >
> >The problem is as follows. Sometimes I need to use some temporary
> >variables.  So I use command tempvar.
> >
> >For example, my do file is the following:
> >
> >use file.dta, clear
> >
> >sort eid
> >tempvar temxxx
> >by eid: gen `temxxx'=_n
> >drop if `temxxx'!=1
> >
> >sort eid
> >
> >save file1.dta, replace
> >
> >The problem is that after I run the whole do file, which will save the
> >data in file1.dta, next time I open file1.dta, I ALWAYS find that there is
> >an additional variable, which is __000000, is added to my data.  All of
> >the values of this variable is 1.  So I have to delete this variable and
> >resave the whole data.    I have run into this problem several times and
> >could not find why and how to fix it.  If this is going to be the way, it
> >seems to me that it is much more convinent that I could just creat a new
> >variable called temxxx and then drop it later on when I don't need it anymore.
> >
> >Is there a way that I can get around this? Thanks.
> >
> >Jian Zhang
> >
> >
> >*
> >*   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/
> >
> >
> >
> >
> >
>
>
> --
> ***************************************************************************
> Jean-Benoit Hardouin
> Biostatisticien
> Observatoire R�gional de la Sant� du Centre
> BP 2439
> 1, rue Porte Madeleine
> 45032 Orl�ans Cedex 1
> t�l : 02 38 74 48 80
> fax : 02 38 74 48 81
> Email : [email protected]
> **************************************************************************
>
> *
> *   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/
>

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