Statalist


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

Re: st: Testing for variable type


From   Eric Booth <[email protected]>
To   [email protected]
Subject   Re: st: Testing for variable type
Date   Mon, 25 Jan 2010 13:34:51 -0600

<>

My last message came through email okay, but was empty on the web version of Statalist (here http://www.stata.com/statalist/archive/2010-01/msg00811.html)...here it is again:


On Jan 25, 2010, at 1:15 PM, Eric Booth wrote:

> <>
> 
> From the -capture- help file:
> 
>       foreach v of local varlist {
>                capture confirm string variable `v'
>                if !_rc {
>                        action for string variables
>                }
>                else {
>                        action for numeric variables 
>                }
>        }
> 
> ...
> 
> for your case you could do something like:
> 
>     foreach v of varlist major1-major3 {
>                capture confirm numeric variable `v'
>                if !_rc {
>                       tostring `v', force replace
>                }
> }
> 
> Also,  you could use -ds- to make a varlist of string or numeric vars to manipulate. (-help ds-)
> 
> 
> ~Eric
> 
> __
> Eric A. Booth
> Public Policy Research Institute
> Texas A&M University
> [email protected]
> Office: +979.845.6754
> 
> 
> On Jan 25, 2010, at 1:06 PM, Bryce Mason wrote:
> 
>> Listers,
>> 
>> 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?
>> 
>> Best,
>> 
>> Bryce
>> 
>> 
>> 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:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/statalist/faq
>> *   http://www.ats.ucla.edu/stat/stata/
> 
> 
> 
> *
> *   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/


*
*   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