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

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

From   Austin Nichols <>
Subject   Re: st: Strange -joinby- behaviour...
Date   Tue, 10 Feb 2009 14:03:35 -0500

David Elliott <>:
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

On Tue, Feb 10, 2009 at 7:58 AM, David Elliott <> 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:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index