Bookmark and Share

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: Program def syntax


From   Nick Cox <njcoxstata@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Program def syntax
Date   Tue, 25 Feb 2014 10:32:17 +0000

There is no black sorcery here. The only nuance here is the difference
between a thing and its name.

You allow -by()- so if you specify -by()- a consequence of the
-syntax- command is that it creates the local macro -by- containing
the name(s) of the variable you specify.

Suppose you specify

... , by(foreign)

then

di `by'

is interpreted by -display- as a request to

di foreign

and (what may be a surprise here) -display- is not in the habit of
displaying entire variables, so as a token of good-will it acts as if
you really meant

di foreign[1]

In your case, you should find that the value 1.2 relates somehow to
your variables and their values in the first observation.

What you want, naturally, is to see the _names_ themselves and to
insist on that you put

di "`by'"

where the " " emphasise to Stata that you want the string interpretation.

(When debugging I sometimes use -macro list- as a quick and dirty way
to get Stata to show the contents of all macros.)

Nick
njcoxstata@gmail.com

On 25 February 2014 10:19, Johannes N. Blumenberg
<blumenberg@politik.uni-mainz.de> wrote:

> I got a small question regarding the program define syntax. I defined a
> program and set its syntax to
> syntax varlist [, BY(varlist) MOreoff]
>
> However, I am unable to access the varlist defined in "by". All that Stata
> returns to me is that the statement is true, when I try to display its
> content with the help of di `by'.
>
> When I put three variables into the by argument Stata returns "1.2". All
> reading in the guidelines etc did not help me.
>
> So, which kind of black sorcery is needed to return the variablelist defined
> in `by'? :)
*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index