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" <[email protected]>
To   <[email protected]>
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: [email protected]
[mailto:[email protected]] On Behalf Of Orion
Whitaker
Sent: Saturday, April 30, 2005 5:24 PM
To: [email protected]
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
[email protected]
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index