Statalist The Stata Listserver


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

st: Re: Function that returns variable type (string, etc.)?


From   "Michael Blasnik" <michael.blasnik@verizon.net>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Re: Function that returns variable type (string, etc.)?
Date   Fri, 17 Nov 2006 10:27:10 -0500

..
Here are a couple of approaches assuming your variable is called myvar

Method 1:
capture confirm string var myvar
if _rc==0 {
...then do stuff with a string var
}
else {
...do stuff with numeric var
}

Method 2:
local vartype: type myvar
if substr("`vartype'",1,3)=="str" { do stuff with string var...
}

Michael Blasnik

----- Original Message ----- From: "Rachel" <academicgirl@gmail.com>
To: <statalist@hsphsun2.harvard.edu>
Sent: Friday, November 17, 2006 10:09 AM
Subject: st: Function that returns variable type (string, etc.)?



I'm looking for a function that returns the type of a given variable.
Specifically, I'd like to know if each variable in a list is a string
or not.

This seems fairly obvious, but I couldn't find it in the documentation
under "Format" or any of the related entries.
*
*   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