Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Using byable in a class member program


From   [email protected] (Vince Wiggins, StataCorp)
To   [email protected]
Subject   Re: st: Using byable in a class member program
Date   Wed, 27 Jun 2007 11:34:05 -0500

Shrenik Shah <[email protected]> asks about combining the -by:- prefix with
class programming.

> It seems that the byable option does not work correctly when used
> with a class member program. (I am using Stata Version 8.2.)  For
> example, if I try to create a test class:

> version 8.2
> class testclass {
> }
> program .test, byable(recall)
> 	if _by() {
> 		disp "by option worked"
> 	}
> end
>
> I find:
>
> . .tc = .testclass.new
>
> . sort index
> 
> . by index: .tc.test
> unrecognized command:  .tc.test invalid command name
> r(199);

The -by:- prefix cannot be combined with class member programs because in a
line like

    . by index: .tc.test

-by:- is modifying a class instance (.tc) and not a program (.test).  In
short, -by:- is not meant to work with member programs.

I have a hard time envisioning how the -by:- prefix could be more useful when
operating on a member program within a specific class instance rather than
operating on normal program, but that does not matter, Shrenik can get his
desired result with a simple wrapper program.  For example,

---------------------------------- BEGIN --- classby.ado --- CUT HERE -------
version 8.2
program classby, byable(recall)
	`0'
end
----------------------------------   END --- classby.ado --- CUT HERE -------

With -classby- in hand, rather than calling -.tc.test- directly, Shrenik can
now type,

    . by index:  classby .tc.test

If the program -.test- needs any of the local macros passed to a byable
program (and this is unusual for byable(recall) programs), he will need to
pass them along where the `0' appears in program -classby-.  For more on these
macros, see [P] byable.

 
-- Vince 
   [email protected]

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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