Statalist


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

Re: st: RE: minor bug in -lookfor-?


From   Sergiy Radyakin <[email protected]>
To   [email protected]
Subject   Re: st: RE: minor bug in -lookfor-?
Date   Mon, 26 Jan 2009 18:18:12 -0500

Dear Jeph,

I think you may not use /* */ comments interactively.
-help comments- reserves this right for the simple *-comments. Here is a quote:
-------------------------------
There are several ways of adding comments in do-files and programs (ado-files).
        1.  begin the line with *
        2.  place the comment between /* and */ delimiters
        3.  begin the comment with //
        4.  begin the comment with ///
Note that the comment indicator * may only be used at the beginning of
a line, but it does have the advantage that it can be used
interactively.
-------------------------------
This explains the age/sex problem that you describe: when issued
interactively it means search for 4 tokens. When in program search for
the first token only. This is clear here:
sysuse auto
label variable foreign `"/*"'
lookfor age /* sex */

              storage  display     value
variable name   type   format      label      variable label
-------------------------------------------------------------------------------
mpg             int    %8.0g                  Mileage (mpg)
foreign         byte   %8.0g       origin     /*

.


Perhaps you'd prefer something like:
lookfor, text(`"mysearchitem"')
but it's quite cumbersome to type.

In any case -lookfor- is implemented as an ado file and is relatively
easy to adjust to taste.

Regards, Sergiy Radyakin





On Mon, Jan 26, 2009 at 5:53 PM, Jeph Herrin <[email protected]> wrote:
> Well, I did put a question mark in the subject line...
>
> But how does the following sit with you?
>
>
> . lookfor age /* sex */
>
>              storage  display     value
> variable name   type   format      label      variable label
> --------------------------------------------------------------------------------------------------------------------------------------
> age             byte   %8.0g                  Age
> sex             byte   %8.0g                  Sex
>
>
> As you say, -lookfor- is functioning exactly as advertised.
> On the other hand, one comes to expect certain behavior from
> Stata commands.  More, if I paste the above line into the do-editor
> and -do- it:
>
> . lookfor age /* sex */
>
>              storage  display     value
> variable name   type   format      label      variable label
> --------------------------------------------------------------------------------------------------------------------------------------
> age             byte   %8.0g                  Age
>
>
> I would argue that it's good style, if nothing else, that a
> command that runs interactively and in a do-file without
> error should return the same results in both contexts.
>
> And yes, I have used -lookfor- in -do-files before, it is a
> handy way of grabbing a list of variables and storing them in
> a local.
>
> Thoughts?
>
>
>
>
>
>
>
>
> Nick Cox wrote:
>>
>> I've got to say that I don't regard this as a bug.
>> -lookfor- does not claim to support options, nor does it do that. So,
>> there's no inconsistency either way in that respect.
>> Nor do I think that there is a good reason to ban commas as input, if
>> that were to be suggested. Commas can be part of strings, no question.
>> As -lookfor- behaves reasonably even when Jeph treats it not quite as
>> intended, wherein lies the bug?
>> Nick [email protected]
>> Jeph Herrin
>>
>> For what it's worth, I was surprised to discover that
>>
>>  lookfor myvar, fullnames
>>
>> produces the same result as
>>
>>  lookfor myvar fullnames
>>
>> That is, if you add any options to -lookfor-, it ignores the
>> comma and treats the options as search strings.
>>
>> On the one hand, the documentation clearly indicates there
>> are no options. On the other, it often happens that I try
>> options that I think might work and expect Stata complain
>> if they are invalid.
>>
>> In this case, I abbreviated -fullnames- to -fu-, and was finding variables
>> that in no way matched -myvar-. Took me a while to
>> puzzle out.
>>
>> *
>> *   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/
>>
> *
> *   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/
>
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index