Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: Unreasonable error "Obs. nos. out of range"


From   Stefan Bernhard <stefanbernhard88@gmail.com>
To   statalist <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Unreasonable error "Obs. nos. out of range"
Date   Mon, 17 Jun 2013 18:36:02 +0200

Thx Nick, so the thing ist that it is actually possible to refer to a
non-existant observation, which caused the confusion.

I then found the error after I knew that the observations had to be
diasspearing.

But I think the way this is handled is somewhat awkward. It should
already tell me that there is no 2nd observation when I try to refer
to it with the if clause :/

best regards, stefan bernhard,



2013/6/17 Nick Cox <njcoxstata@gmail.com>:
> Difficult to comment given this little information, but
>
> 0. It is possible to have variables defined but no observations.
>
> 1. Possibly more to the point, the -replace- will certainly fail if _N
> < 2 but it's not necessarily an error otherwise to refer to -cats[2]-
> when it doesn't exist. If -cats- exists as a variable then any
> references to subscripts that don't correspond to observation numbers
> are interpreted as missing.
>
> 2. However, your code does imply that -cats[2]- is being treated as
> zero. Could you confirm that -local bak- is not defined before the
> code you cite?
>
> Either way, -list-ing the data would make your situation clearer.
>
> This example bears on #1.
>
> clear
> set obs 1
> gen cats = 1
> if cats[2] == 0 {
>       di "problem 1"
> }
> else di "problem 2"
>
> Nick
> njcoxstata@gmail.com
>
>
> On 17 June 2013 15:21, Stefan Bernhard <stefanbernhard88@gmail.com> wrote:
>> dear statalisters,
>>
>> i have a piece of looping code over different variables and all
>> observations, and an excerpt of the trace shows this:
>>
>> = if cats[2] == 0 {
>>   local bak = 0
>>   }
>> - noi di as text "bak is `bak'"
>> = noi di as text "bak is 0"
>> bak is 0
>> - replace `var' = 1 in `i'
>> = replace cats = 1 in 2
>> Obs. nos. out of range
>>
>>
>> This makes no sense at all to me.
>>
>> In the first line, it successfully uses the value of cats of
>> observations number 2 to define the local bak as 0.
>>
>> Few lines later, it acts as if there was no more observations number 2
>> and cannot replace the number of cats with 1 in observation number 2.
>>
>> Why does it say Obs. nos. out of range ?
>>
>> regards, stefan bernhard,
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/faqs/resources/statalist-faq/
>> *   http://www.ats.ucla.edu/stat/stata/
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index