Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: AW: AW: Reference column without knowing variable name?


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: AW: AW: Reference column without knowing variable name?
Date   Wed, 3 Mar 2010 10:50:09 +0100

<> 

" ds (resp. ds2 or ds3) is great to list vars based on different attributes but not necessary here because you can use "*" or "_all"."


That depends on the kind of transformation you have in mind. If it applies to all vars without exception, then this is a viable strategy. Most of the time, you want separate things done to strings and numeric vars, though...




HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Stefan.Gawrich@hlpug.hessen.de
Gesendet: Mittwoch, 3. März 2010 10:40
An: statalist@hsphsun2.harvard.edu
Betreff: st: AW: Reference column without knowing variable name?

Martins solution is perfectly right. 
I want to add a very basic solution. 

What you need for that task is 
- a macro with all vars to cycle through and 
- an index to decide if the actual var should be altered or not. 

ds (resp. ds2 or ds3) is great to list vars based on different attributes but not necessary here because you can use "*" or "_all". 

foreach var of varlist * {
local i = `i' + 1
if mod(`i'-1,3)== 0 rename `var' yes__`var'
}


Local i counts the loops/variables processed. 
mod(`i',3) is 0 for i = 0,3,6,9,...
=> mod(`i'-1,3) is 0 for `i' = 1,4,7,...


Stefan Gawrich








*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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   |   Site index