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

st: RE: How to get the variable name


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: How to get the variable name
Date   Fri, 18 Jun 2004 10:14:42 +0100

In addition to other suggestions, I also recommend -ds-. 
Note that this was updated on 17 June 2003, so the 
manual help is less up-to-date than the on-line help. 

-ds- returns a list of variable names in r(varlist). There are 
several filters allowed. Here are some examples from the 
help. 

 All variables:

        . ds

 All string variables:

        . ds, has(type string)
        . edit `r(varlist)'

 All str1, str2, str3, str4 variables:

        . ds, has(type 1/4)

 All numeric variables:

        . ds, has(type numeric)
        . order `r(varlist)'

        . ds, has(type numeric)
        . summarize `r(varlist)'

 All byte or int variables:

        . ds, has(type byte int)

 All float variables:

        . ds, has(type float)

 All variables that are not float:

        . ds, not(type float)

 All variables with value labels attached:

        . ds, has(vall)

 All variables with the value label origin attached:

	. ds, has(vall origin)

  All date variables, i.e. those with formats %d*, %-d*, %t* or %-t*:

	 . ds, has(format %d* %-d* %t* %-t*)

 Variables with left-justified string formats:

        . ds, has(format %-*s)

 Variables with comma formats:

       . ds, has(format *c)

 Variables with characteristics defined:

        . ds, has(char)

Nick 
n.j.cox@durham.ac.uk 

Maoyong Fan
> 
> 	I just wonder how can I get the list of varibale name 
> automatically instead of looking at describe list.  If I can 
> get the list of the variable name and store them into a local 
> variable, I could use "foreach var in local var" to do data 
> management on each variable.  Because I have do deal with 
> more than 100 stata data files and do some data management 
> for each data file.  Using loop will same a lot of time than 
> do that manually.	

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