Bookmark and Share

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


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

Re: st: _00001 already define error using egen xx=group()


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: _00001 already define error using egen xx=group()
Date   Tue, 27 Sep 2011 10:09:52 +0100

Excellent diagnosis. I'd put my bets on this. It would also explain
the otherwise bizarre fact that this started happening a while ago.

Evidently Stata keeps separate track of (1) what variable names are in
use in the dataset (2) what temporary names have been used in the
current session, and this is exactly what you want because overwriting
an existing variable that you -save-d earlier would destroy data.

It's not good style to keep temporary variables under their original
names, but it's certainly not illegal.

Barry should note that temporary variable names begin with a double
underscore. If he wants that temporary variable, -rename- is called
for rather than -drop-.

Nick

On Tue, Sep 27, 2011 at 9:39 AM, Seed, Paul <[email protected]> wrote:

> I recognise the error messages that Barry Quinn has
> been getting. They happen when I save a permanent file
> containing temporary variables.
> (Of course Barry Quinn's problem might be due to something
> else, but he should try this.)
>
> Here is how to do it & fix it.
> It involves multiple calls of Stata.
> (Repeatedly opening and closing fresh instances).
>
> ****************
> * First call of Stata *
>
> sysuse auto
> tempvar v1
> gen `v1' = mpg*mpg
> save myfile, replace
> exit, clear
> ******************
>
> ****************
> * Second call of Stata *
>
> use myfile
> desc _all
> tempvar v2
> // The next line creates the error //
> cap noi gen `v2' = weight*weight
>
> // This is the fix //
> cap drop  __00*  // drop any temporary variables //
> tempvar v2
> // The line no longer creates an error //
> gen `v2' = weight*weight
>
> ******************
>
> Alternatively, you can explicitly drop the temporary variables before saving:
> ****************
> * First call of Stata *
>
> sysuse auto
> tempvar v1
> gen `v1' = mpg*mpg
>
> cap drop __00*
> save myfile, replace
> exit, clear
> ******************
>
> ****************
> * Second call of Stata *
>
> use myfile
> desc _all
> tempvar v2
> gen `v2' = weight*weight
> ******************
>
>
>
> The fault is due to saving a permanent data set containing temporary variables.
> The solution is to delete all temporary variables before saving or using the dataset.
>
> Over the years I have learned to reserve temporary variables for
> ado files; and to use only ordinary variables in creating a dataset.
> Unwanted variables I delete before saving.
>
> I am using Stata version 11.2, but I doubt if this problem has been removed in later versions.
> This is the first time I have seen it referred to.
>

> Date: Mon, 26 Sep 2011 08:50:03 +0100
> From: Nick Cox <[email protected]>
> Subject: Re: st: _00001 already define error using egen xx=group()
>
> This is a very worrying kind of error message. You are getting
> messages about temporary variables that could mean that not just this
> calculation but much else in Stata will not work properly.
>
> Is this Stata 12? (Statalist convention is that you are presumed to be
> using the latest version unless you state otherwise.)
>
> Show the result of
>
> . su insample oneyear
>
> Did you -update- your Stata recently? You may have done this
> incompletely. Run -update query-.
>
> I can't repeat your calculation without your data. Does this work properly?
>
> clear
> sysuse auto
> egen group = group(foreign rep78)
>
> On Mon, Sep 26, 2011 at 8:32 AM, Barry Quinn <[email protected]> wrote:
>
>>  I have been running the egen xx= group() command to produce coding which allows me to choose 3 of the four possible pairs when combining two binary variables.
>> Recently the above error has started to appear.
>>
>> Example:
>>
>> Say I have two binary variables D(0,1) & B(0,1)
>> I want to run a command choosing the groups (D=0 & B=1) , (D=1 & B=0) , (D=1 & B=1) and not the group (D=0 & B=0).
>> I find the egen group() command does this well by creating a variable from 1 to 4 for each possible combination of the two binary variables and then I run my command using
>> ......if  xx>1
>>
>> My problem is when I run this command I get the error
>> __000000 already defined
>> __000001 already defined
>>
>> For reference here is the full code I am running and the resultant error:
>>
>> .clear
>> . use panelcleanappend
>> . capture drop w
>> . gen w=runiform()
>> . sort treat w
>> . capture drop insample
>> . gen insample=_n<=1000
>> . drop id1
>> . egen id1=group(insample oneyear)
>> __000000 already defined
>> __000001 already defined
>>
>> Any help with this error or a possible another way to choose the above groups would be appreciated

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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