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

Re: st: Suggestion for -confirm var- option


From   wgould@stata.com (William Gould, Stata)
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Suggestion for -confirm var- option
Date   Mon, 15 Mar 2004 08:24:39 -0600

Kaleb Michaud <kaleb@stanford.edu> writes, 

> [...] debug a program, when I realized that the -confirm var- command does
> not require the variable to be spelled out fully.
>
> For example, suppose you have a program that looks to see if the variable
> "car" exists.  If it doesn't, it creates or merges it in.  But, if I have a
> variable called cartoon and not car in the data:
>
> . confirm var car
>
> gives us _rc == 0 even though the var car doesn't exist and the var cartoon 
> does.  Any way that the Stata powers that be could add an "exact" option
> [...]

That's a good idea.  In the meantime, the "right" way to confirm whether 
variable "car", not abbreviated, exists is

        . confirm name car
        . confirm new var car

or, in a programming context, 

        . confirm name `possiblevar'
        . confirm new var `possiblevar'

The first statement verifies that `possiblevar' could be a variable name, that
it does not violate Stata's naming conventions.  The second line verifies that
a variable named `possiblevar' does not already exist.

-- Bill
wgould@stata.com
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index