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: Unreasonable error "Obs. nos. out of range"
From
Stefan Bernhard <[email protected]>
To
statalist <[email protected]>
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 <[email protected]>:
> 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
> [email protected]
>
>
> On 17 June 2013 15:21, Stefan Bernhard <[email protected]> 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/