Statalist


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

Re: st: Strange -joinby- behaviour...


From   Austin Nichols <austinnichols@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Strange -joinby- behaviour...
Date   Tue, 10 Feb 2009 14:03:35 -0500

David Elliott <dcelliott@gmail.com>:
I would say it is a more generic problem than rewriting -joinby- can
address, but rewriting -by- (so that a variable would be created even
when there are no categories or observation over which to loop, or an
error would be issued) would fix it, I think:

clear all
set obs 100
g y=.
sort y
by y: g h=uniform()
sort y h
*by var everywhere missing works fine
clear all
g y=.
sort y
by y: g h=uniform()
sort y h
*by var with no obs defined "fails"

That would clearly be up to Stata developers, and it is of course
possible that some other set of commands depends on no variable being
created in this kind of situation...  but I think if -by- issued an
error r(2000) when using zero observations, and therefore doing
nothing, it would generally be a good thing.

A similar problem occurs when looping over items with e.g. -foreach-
where no items are in the list, and nothing inside the list is done,
but that _can_ be desirable behavior.  I think it is probably best
left up to user-programmers to be aware of these kinds of situations,
and watch out for them.  Better error messages never hurt, of course,
but in this case they could add many lines to many programs (not just
-joinby-).


On Tue, Feb 10, 2009 at 7:58 AM, David Elliott <dcelliott@gmail.com> wrote:
> Glad you got it sorted, Neil.
>
> This however begs for a better error trapping and messaging in
> -joinby- as your situation would not be a unique case.
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index