Statalist The Stata Listserver


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

st: RE: a question about tempvar


From   "Newson, Roger B" <[email protected]>
To   <[email protected]>
Subject   st: RE: a question about tempvar
Date   Tue, 7 Feb 2006 13:29:25 -0000

You need to insert

drop `temxxx'

before your -save- statement. Temporary variables defined in a do-file
survive until the end of execution of the do-file unless explicitly
dropped.

Hope this helps.

Roger


Roger Newson
Lecturer in Medical Statistics
POSTAL ADDRESS:
Respiratory Epidemiology and Public Health Group
National Heart and Lung Institute at Imperial College London
St Mary's Campus
Norfolk Place
London W2 1PG
STREET ADDRESS:
Respiratory Epidemiology and Public Health Group
National Heart and Lung Institute at Imperial College London
47 Praed Street
Paddington
London W1 1NR
TELEPHONE: (+44) 020 7594 0939
FAX: (+44) 020 7594 0942
EMAIL: [email protected]
WEBSITE: http://www.kcl-phs.org.uk/rogernewson/
Opinions expressed are those of the author, not of the institution.


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Jian Zhang
Sent: 06 February 2006 23:40
To: [email protected]
Subject: st: a question about tempvar

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/

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