Statalist The Stata Listserver


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

RE: st: a question about tempvar


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   RE: st: a question about tempvar
Date   Mon, 6 Feb 2006 20:35:54 -0600

tempvar, tempname, and tempfile exist while the program or do file is
running, but are dropped once the it ends.  In this case, the -save
file1d.dta- is part of do file so the temporary variables are saved.  

[P] macro, page 191, has a discussion of the advantages of temporary
variables.

This could be reduced to 3-lines:

use file.dta,clear
bysort com: keep if _n == 1
save file1.dta, replace

Hope this helps,
Scott


> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Jian Zhang
> Sent: Monday, February 06, 2006 7:36 PM
> To: [email protected]
> Subject: Re: st: a question about tempvar
> 
> 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
> 


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