Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Is there a command that returns a Variable's Type?


From   "Frank de Libero" <fedmerchant@comcast.net>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Is there a command that returns a Variable's Type?
Date   Sat, 30 Apr 2005 19:03:38 -0700

A macro extended function should get you there:

Local v : type var

For example if you replace 

if ( type(`v')==0 ) {

with (or some modification to suit your needs)

if inlist("`: type `v''","int","byt","long") {

I think you'll be able to do what you want.

See whelp extended_fcn

..Frank

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Orion
Whitaker
Sent: Saturday, April 30, 2005 5:24 PM
To: statalist@hsphsun2.harvard.edu
Subject: st: Is there a command that returns a Variable's Type?

I'd like to do different tests depending on a variables type (continuous
vs discrete).  

While "codebook" displays "units" that would give me a clue (1 for
discrete, 0.1 & 0.01... for continuous) I can't seem to find a command
or function that would give me a variable's type.

Something like:       uses(varname)  returning   1 or 0.1 or 0.01...
                            or   type(varname)   returning  "byte"
"int" "double"...

I imagine doing something like:

foreach v of varlist var1 var2 var3... {
    if ( type(`v')==0 ) {
    do some discrete tests
    }
        else {
            if ( type(`v')==1 {
            do some continuous tests
            }
         }
}




--
Orion C. Whitaker
Johns Hopkins School of Public Health
Johns Hopkins School of Medicine
owhitak1@jhmi.edu
*
*   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/

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