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 <[email protected]>
To   [email protected]
Subject   Re: st: re: egen with error after set obs erases obs
Date   Tue, 8 Feb 2011 18:12:31 +0000

Good question. In this new example I think your guess about how Stata
would behave is fair, but evidently Stata is set up so that you have
to reissue -set obs 10-. You need a real expert to explain why.

Nick

On Tue, Feb 8, 2011 at 4:59 PM, Airey, David C
<[email protected]> 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
>> [email protected]
>>
>>
>>
>>> 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