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]

From |
Nick Cox <njcoxstata@gmail.com> |

To |
"statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |

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

Date |
Mon, 17 Jun 2013 17:42:25 +0100 |

You have not answered all my questions about your code. I don't know what your programming criteria are here. I note only as one common example that references to [_n-1] and [_n+1] are commonplace and deliberate. I don't want to see error messages that myvar[0] and myvar[_N+1] don't exist. I know that already. Nick njcoxstata@gmail.com On 17 June 2013 17:36, Stefan Bernhard <stefanbernhard88@gmail.com> wrote: > 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/ * * 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/

**Follow-Ups**:**Re: st: Unreasonable error "Obs. nos. out of range"***From:*Stefan Bernhard <stefanbernhard88@gmail.com>

**References**:**st: Unreasonable error "Obs. nos. out of range"***From:*Stefan Bernhard <stefanbernhard88@gmail.com>

**Re: st: Unreasonable error "Obs. nos. out of range"***From:*Nick Cox <njcoxstata@gmail.com>

**Re: st: Unreasonable error "Obs. nos. out of range"***From:*Stefan Bernhard <stefanbernhard88@gmail.com>

- Prev by Date:
**Re: st: Unreasonable error "Obs. nos. out of range"** - Next by Date:
**Re: st: Unreasonable error "Obs. nos. out of range"** - Previous by thread:
**Re: st: Unreasonable error "Obs. nos. out of range"** - Next by thread:
**Re: st: Unreasonable error "Obs. nos. out of range"** - Index(es):