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

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


From   [email protected]
To   [email protected]
Subject   Re: st: RE: New command in SSC: -checkfor2-
Date   Tue, 20 Sep 2005 09:43:29 -0400

Thanks Nick and Jean-Benoit,

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
you.
Best regards.
Amadou.


[email protected] wrote: -----

To: <[email protected]>
From: "Nick Cox" <[email protected]>
Sent by: [email protected]
Date: 09/19/2005 06:38PM
Subject: RE: st: RE: New command in SSC: -checkfor2-


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'
     }

     di

     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'"
     }
end

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.

Otherwise I agree with all Jean-Benoit's comments.

I know the World Bank would like us all to think
globally, but rclass in my view too is the way
to go here.

Nick
[email protected]

Jean-Benoit Hardouin

> I find several drawbacks in the programing of -checkfor2- :
>       - the use of "anything" instead of "varlist" in the
> syntax command
> avoids to use list of variables as var1-var10 or var*
>       - the idea to use a global macro variable is, from my
> mind, a bad
> idea (I prefer a "return" command)



*
*   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/

*
*   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