[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: Testing for variable type

From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: RE: Testing for variable type
Date   Mon, 25 Jan 2010 20:25:06 +0100


Here is an example. - tostring major3, replace- is much faster, though...

set obs 1

gen str3 major1="yes"
gen str2 major2="no"
gen major3=3

qui ds, not(type string)

foreach x in `r(varlist)'{
	gen temp=string(`x')
	drop `x'
	rename temp `x'


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Bryce Mason
Sent: Montag, 25. Januar 2010 20:06
To: [email protected]
Subject: st: Testing for variable type


Anyone know of a function that can be used to return variable type?  
For example, I'd like to get a return value on a variable and, if it  
is numeric, convert it to string. Something like "vartype" the  
following pseudocode:

variables: major1 (string), major2 (string), major3 (numeric, since it  
happens to be empty this year)

foreach x in major1 major2 major3 {;
if vartype(`x') is numeric {;
	gen temp=string(`x');
	drop `x';
	rename temp `x';

Any thoughts?



Bryce Mason, Ph.D.
Director of Institutional Research
Loyola Marymount University
1 LMU Drive | Los Angeles, CA 90045

b:	4823 University Hall
w:	(310) 258-8838
f:	(310) 338-1841
e:	[email protected]

*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index