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

Re: st: How to get the variable name


From   "Lee Chuntao" <[email protected]>
To   <[email protected]>
Subject   Re: st: How to get the variable name
Date   Fri, 18 Jun 2004 14:37:36 +0800

Hello Maoyang,

   You can also do the following


    foreach var of varlist * {
        command referring to `v'
                                     }

there is one problem with this program, if there are some variables are
string variables, and the command need to deal with only non-string ones,
you should add a capture to the command, e.g.

    foreach var of varlist * {
        capture replace `v'=`v'*`v'
                                     }


or simply list the variable names:

   foreach var in var1 var2 ... varn {
        capture replace `v'=`v'*`v'
                                     }





other
----- Original Message ----- 
From: "Renzo Comolli" <[email protected]>
To: <[email protected]>
Sent: Friday, June 18, 2004 2:20 PM
Subject: Re: st: How to get the variable name


> Dear Maoyong,
>
> I am not sure what you are asking about, but if you are asking to perform
> the same operation on all variables, then do the following
>
> foreach v of varlist _all {
>  command referring to `v'
> }
>
>
> Best,
> Renzo
>
> --------------------------------------------------------------------------
--
> ----
> *From   "Maoyong Fan" <[email protected]>
> To   "statalist" <[email protected]>
> Subject   st: How to get the variable name
> Date   Thu, 17 Jun 2004 22:58:12 -0800
>
> --------------------------------------------------------------------------
--
> ----
>
> Dear Friends,
>
> 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.
>
> Warm regards,
>
> Maoyong Fan
>
>
> *
> *   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