Statalist


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

RE: st: macro for the type of a variable (string/numeric)


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: macro for the type of a variable (string/numeric)
Date   Mon, 21 Apr 2008 19:13:44 +0100

Jacob was interested in the coarser distinction between numeric and
string. 

This is just one step down the line from Austin's approach here. 

sysuse auto
foreach v of varlist _all {
	loc type = substr("`: type `v''", 1, 3) 
	if "`type'" == "str" { 
		di as res "`v'" as txt " is string" 
	} 
	else di as res "`v'" as txt " is numeric"
}

Also see help on -confirm-. 

Nick
[email protected] 

Austin Nichols

See the second entry under
help extended_fcn

or try:
sysuse auto
foreach v of varlist _all {
 loc type: type `v'
 di as res "`v'" as txt " is type" as res " `type'"
}

On Mon, Apr 21, 2008 at 11:01 AM, Jacob Wegelin <[email protected]>
wrote:

> The following program is a kluge to determine the type of a variable
and to
> assign a string to a local macro which tells us the type.  Is there
some
> better way? For instance, "return list" after "describe myvar" or
"codebook
> myvar" does not tell us this.

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