Statalist


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

Re: st: check if string or numeric


From   David Kantor <[email protected]>
To   [email protected]
Subject   Re: st: check if string or numeric
Date   Mon, 06 Oct 2008 17:03:32 -0400

At 04:44 PM 10/6/2008, Jacob A. Wegelin wrote:
I would like to check for type of variable (string, numeric, etc) in a program, and then take action on the basis of the type. [...]
How about...
local typ: type varname

then test whether substr("`typ'" , 1, 3) == "str"

You can be more concise by compressing this into one expression:
substr("`:type varname'" , 1, 3) == "str"

And of course, substitute `1' for varname in your program.

HTH
--David

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index