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
"Eric A. Booth" <[email protected]>
To
[email protected]
Subject
Re: st: catching variable mismatch in the data
Date
Fri, 13 Sep 2013 06:07:39 -0500
<>
Hi Paul:
It appears you want to stop your do file if there is any variable
present that has a variable name of the pattern var4???.
If you find them, then you want to stop your do-file (based on the use
of the error message and -exit- in your loop).
Your loop is failing for a few reasons. First , var4### is illegal;
instead, you want var4???. Also, the second line with 'capture
confirm...' is irrelevant when you start the loop with 'foreach x1 of
varlist var4??? { ' because if there were no var4??? in your dataset
the loop would stop there and say 'variable 4??? not found', having
never reached the 'capture confirm...' lines nested below.
Instead, I think you can put these 2 lines in your do-file to get the
functionality you seek:
**
cap noi ds var4???
if `"`r(varlist)'"' != "" exit
**
- Eric
On Fri, Sep 13, 2013 at 5:35 AM, Paul Byatta <[email protected]> wrote:
> 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/
*
* 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/