Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: to check if a variable already exists


From   Jacob Wegelin <jwegelin@vcu.edu>
To   Eva Poen <eva.poen@gmail.com>
Subject   Re: st: to check if a variable already exists
Date   Mon, 6 Oct 2008 18:46:50 -0400 (EDT)

Dear Eva,

Thank you. For the record (in case anyone else is as in need of this information as I am), here is a way to do it.

capture program drop myTRY
program define myTRY
	capture confirm variable `1'
	if _rc==0 {
		di "`1' already exists, so ..."
		}
	else {
		di "`1' does not exist yet, so maybe we want to first generate it ..."
		}
end

myTRY "dogAndCAT"

myTRY dogAndCat

myTRY Age

Jake

Re: st: to check if a variable already exists

From	  "Eva Poen" <eva.poen@gmail.com>
To	  statalist@hsphsun2.harvard.edu
Subject	  Re: st: to check if a variable already exists
Date	  Mon, 6 Oct 2008 23:26:10 +0100
 It's  -help confirm-, again.

If you do programming, NC151 will be useful (see a recent announcement
on this list).

Eva

2008/10/6 Jacob Wegelin <jwegelin@vcu.edu>:
Is there a way to check whether a variable is already defined, already
exists? I'd like to write code of the following sort:


if (variable called performance is not yet defined) {
       gen performance=.
       }
replace performance=5 if name=George

Thanks for any ideas

Jake

Jacob A. Wegelin
jwegelin@vcu.edu Assistant Professor
Department of Biostatistics
Virginia Commonwealth University
730 East Broad Street Room 3006
P. O. Box 980032
Richmond VA 23298-0032
U.S.A. http://www.people.vcu.edu/~jwegelin
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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