Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Temporary variables saved by accident

From   Adrian Sayers <>
Subject   st: Temporary variables saved by accident
Date   Wed, 09 Jan 2013 13:18:09 +0000

Hi All,

I have come across some strange behaviour. After saving a file which uses temporary variables, the temporary variables are also saved, and converted to permanent variables. I had assumed this would not happen?

If i run all the code together i have no problems.
But if i run part 1 , then part 2 i get an error message of "__000002 already defined"

I am running version 21.1

// Part 1
	set obs 100
		gen age_1 = 10

tempvar P n
	gen `P' = uniform()
		sort `P'
			gen `n' = _n

save error_test.dta , replace

// Part 2
	use  error_test.dta  , clear
	hist age

so the work around is

drop __00*

But why does this happen?

Many thanks


*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index