Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: Re: st: RE: New command in SSC: -checkfor2-

Subject   Re: Re: st: RE: New command in SSC: -checkfor2-
Date   Tue, 20 Sep 2005 10:31:48 -0400

I think that will be useful (:-)).

                      n j cox                                                                                                                  
                      <>           To:                                                
                      Sent by:                         cc:                                                                                     
                      owner-statalist@hsphsun2.        Subject:  Re: Re: st: RE: New command in SSC: -checkfor2-                               
                      09/20/2005 10:20 AM                                                                                                      
                      Please respond to                                                                                                        

-isvar- just does one of the three things that
-checkfor2- does. That alone is sufficient grounds
for what I said in my previous posting.

It seems from your explanation of the background
here that -isvar- may have some use beyond this thread.
I will write a help file and send it to Kit Baum
for posting on SSC when I can.


 >>> Amadou Diallo

Well, for a long time, checkfor and
its latter version checkfor2 have done
a good job in achieving what I want
and that was the most important for me.
As long as they were doing the job, I did
not find the time, nor the courage I must add,
to refine them.

I am working with DHS data for some
months actually. The problem is that,
despite the comparability of the datasets,
sometimes a program which loops across
datasets will crash, when a variable exists
in one set and not in the other. So checkfor2
"sweeps" the data first, and them use the "available"
variables to perform other tasks.

But, and this is big BUT, checkfor2 is not well
written enough. I guess I'll learn by doing over time.
For the moment, I demand a little indulgence.
Obviously, checkfor2 is not esthetical enough as other
stata programs. I hope the program will improve
enough to meet stata minimum standards.
I am working on it. Jean-Benoit has sent me privately
some thoughts about improvements and I want to
aknowledge that and thank him. I will make the necessary
changes and resubmit.

Out of curiosity, why isvar is not a replacement
for checkfor2? It is doing exactly the same thing and
is cleaner. Here you can see the touch of great programmers.
Remember, the first purpose of checkfor2 is
to separate existing and non-existing variables.
I vote for it and will be more incline in the future to use it after
some minimum modifications, in place of checkfor2.

Again, I want to thank you all to allow me to learn with

Nick Cox

There is no clash here. Let's back track:

Amadou Diallo wants to be able to type a list
of (possible) variable names and be told which
are real variable names and which aren't.

If Amadou were to try, for example,

. sysuse auto

. d mpg disp frog toad newt darwin einstein newton price

Then -describe- just chokes on the first non-variable
name, in this case "frog". -describe- won't tell
Amadou that "toad newt darwin einstein newton"
are also non-variable names. Same is true for e.g.
-ds-. In my own view this is a feature, as I have never
wanted what Amadou wants here, but the issue is how
to write a program to deliver on that.

Now in designing a program to get round this,
Amadou faces what looks like Catch-22.

syntax varlist

is out of the question, because those non-variable
names will never get past border control. At the
first such, it's all up. So any program starting with
-syntax varlist- will not work, insofar as the bad
names other than the first just will not be displayed.

Amadou worked that out, and chose

syntax anything

But it looks at first sight as if thereby the programmer
is giving up on nice features that many users exploit
all the time with varlists, such as wildcards and hyphenated lists.

But with -syntax anything- you can have, well, anything
as input. You just have to arrange to process it according to
your precise desires. So that -anything- can be, or
can include a varlist, or several varlists interspersed
with other stuff: it's just that -syntax- won't treat it as such.

Enough of the arm-waving. This code sketch shows
one solution to that desire. I loop over the input
with -foreach-, much faster than a -while- and -mac shift-.

*! NJC 1.0.0 19 Sept 2005
program isvar, rclass
      version 8
      syntax anything

      foreach v of local anything {
           capture unab V : `v'
           if _rc == 0 local varlist `varlist' `V'
           else        local badlist `badlist' `v'


      if "`varlist'" != "" {
           local n : word count `varlist'
           local what = plural(`n', "variable")
           di as txt "{p}`what': `varlist'{p_end}"
           return local varlist "`varlist'"

      if "`badlist'" != "" {
           local n : word count `badlist'
           local what = plural(`n', "not variable")
           di as txt "{p}`what': `badlist'{p_end}"
           return local badlist "`badlist'"

This isn't a substitute for -checkfor2-. -checkfor2-
bundles three things together, a check for good
and bad variable names, a report on number of
missings and summary statistics for any good
variable names, so the last two things aren't touched.

I couldn't find a -checkfor-, not that that matters.

*   For searches and help try:

*   For searches and help try:

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