Orion
see <<help extended_fcn>> for the syntax of extended macros.
For example (and using a common construct to dispense with explictly naming the
macro):
. sysuse auto
. foreach var of varlist _all {
2. display " `var' " _col(20) "`: type `var''"
3. }
make str18
price int
mpg int
rep78 int
headroom float
trunk int
weight int
length int
turn int
displacement int
gear_ratio float
foreign byte
In case your font makes all those quotes hard to decipher:
"`: type `var''"
is
dq lsq : type lsq var rsq rsq dq
Perhaps closer to the program fragment you will need:
. foreach var of varlist price headroom displacement gear_ratio foreign {
2. if "`:type `var''" == "float" {
3. di "`var' is floating point"
4. }
5. }
headroom is floating point
gear_ratio is floating point
Phil
Quoting Orion Whitaker <[email protected]>:
> 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/
>
--
Philip Ryan
Associate Professor
Department of Public Health
University of Adelaide
AUSTRALIA
CRICOS Provider Number 00123M
-----------------------------------------------------------
This email message is intended only for the addressee(s)
and contains information that may be confidential and/or
copyright. If you are not the intended recipient please
notify the sender by reply email and immediately delete
this email. Use, disclosure or reproduction of this email
by anyone other than the intended recipient(s) is strictly
prohibited. No representation is made that this email or
any attachments are free of viruses. Virus scanning is
recommended and is the responsibility of the recipient.
*
* 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/