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: re: egen with error after set obs erases obs


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: re: egen with error after set obs erases obs
Date   Tue, 8 Feb 2011 18:34:18 +0000

This tip would help avoid the problem it describes. But as I already
explained: do not blame -egen- for erasing data that was never there.

On Tue, Feb 8, 2011 at 6:14 PM, Andrew Dyck <andrew@andrewdyck.com> wrote:
> Dave, I understand where you are coming from. When working from a
> do-file this isn't really an issue but I've encountered this several
> times while working with Stata interactively. When generating a dummy
> dataset I'll start with something like this:
>
> set obs 100
> egen var1 = seq()\
>
> But, as I often do, I hit the slash and return key at the same time
> and an error is produced. Now trying to reissue egen will create var1
> with zero observations. I'm sure there is a reason behind why this
> happens but to avoid it, when creating a dummy dataset my first two
> commands are:
>
> set obs 100
> gen var = 1
>
> I create the variable to hold the observations at 100 no matter how
> many mistakes I make typing and even if my fat fingers hit the slash
> key, an error after -gen- doesn't reset the observations the same way
> -egen- does.
>
> Cheers,
> Andrew
>
> On Tue, Feb 8, 2011 at 8:59 AM, Airey, David C
> <david.airey@vanderbilt.edu> wrote:
>>
>> .
>>
>> Thanks. I'm still confused.
>>
>> When I have the editor open, and I type:
>>
>> set obs 70
>>
>> the rows 1-70 are enabled.
>>
>> Then I issue the incorrect egen command, and those enabled rows revert to the state before the set obs 70 command was issue.
>>
>> I guess I would have thought the egen command would not interfere with the result, even if it were no data, of the set obs 70 command.
>>
>> Compare these command sequences below:
>>
>> clear
>> set obs 10
>> egen x1 = seq(), from(1) to(10) block(1)
>> gen x2 = _n
>>
>> vs
>>
>> clear
>> set obs 10
>> egen x1 = seq() from(1) to(10) block(1)
>> gen x2 = _n
>>
>> I would have thought the second sequence would still have created x2 for 10 obs. But it doesn't.
>>
>> -Dave
>>
>>
>> > Not so, but it's not a very short story.
>> >
>> > First, your -egen- call is illegal. -from(1) to(5) block(14)- are all options. It is true that the error message is a little cryptic. But at the point of complaint Stata is prepared to see stuff matching
>> >
>> > syntax [if] [in] [, *]
>> >
>> > whereas it sees
>> >
>> > from(1) to(5) block(14)
>> >
>> > That does not match the syntax. In the absence of a comma, Stata chokes on the first token, namely "from", and interprets it as a illegal attempt to specify a varlist. Whether or not you have such a variable, such syntax is illegal, and you get thrown out of -egen- early on.
>> >
>> > You just need to specify the comma.
>> >
>> > Now in terms of your claim: You never had any data to erase.
>> >
>> > You started with no data, and -egen- never created the variable you asked; it didn't get that far.
>> >
>> > -set obs #- does not itself create observations when there are as no yet no variables; it is just a declaration of intent on your part acknowledged by Stata. The logic is simple: -set obs #- starting from scratch could not create observations because it would not know which variables to fill.
>> >
>> > Nick
>> > n.j.cox@durham.ac.uk
>> >
>> >
>> >
>> >> I noticed these commands
>> >>
>> >> . set obs 70
>> >> obs was 0, now 70
>> >>
>> >> . egen cell = seq() from(1) to(5) block(14)
>> >> varlist not allowed
>> >> r(101);
>> >>
>> >> result in 0 observations on my Stata 11 copy for the Mac. After the egen error, I should still have 70 observations. After doing this I have to set obs 70 again before proceeding.

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