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: catching variable mismatch in the data


From   daniel klein <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: catching variable mismatch in the data
Date   Fri, 13 Sep 2013 14:17:44 +0200

Paul,

I think I did not fully understand what you are trying to do here, but
I am sure your code is not the way to go.

First, note that var4### is not a valid varlist. A varlist allows the
three wildcars *, ? and ~ , and these three characters only. The #
character may be used with -rename- and in factor variables notation
to specify interactions.

Another problem with your code is, that your -confirm- statement is
redundant.  Here is why. Coding

... of varlist <foo>

tells Stata to interpret <foo> as a variable list -- meanig as valid
variables in the dataset. If <foo> is not a variable in the dataset
Stata will issue an error message and abort. Therefore every <foo>
that does not trigger an error in the opening loop statement must be a
valid variable name in the datatset and will be confimed as such by
-confirm-, returning a 0 return code.

Could you rephrase your problem? That is, what exactly do you mean
when you say "foreign variable"? What do you consider to be a variable
name "mismatch"?

Best
Daniel

-- 
Hi Statalist

I writing lines of commands that will alert me whenever there is a
mismatch between variable names. I know there is a mismatch when the
dataset contains a foreign variable name. I also know the foreign
variable name/s will take the prefix of "var" and end with with a
number greater than 4000 (because the total non-foreign variables are
4000).

The commands I have so far

            foreach x1 of varlist var4###{
            capture confirm variable `x1'
              if _rc != 0 {
                display as err "There is a mismatch between variable
names in the data"
                exit _rc
              }


I know based on an earlier discussion on this list (Re: st: -confirm
variable- does not accept varlist (wildcards)) that "capture confirm"
command doesnt accept varlist, but does somebody have any alternative
suggestions on how to programmatically achieve my goal above.


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