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, is already up and running.

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

st: AW: Reference column without knowing variable name?

From   <>
To   <>
Subject   st: AW: Reference column without knowing variable name?
Date   Wed, 3 Mar 2010 10:39:35 +0100

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:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index