Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: AW: Reference column without knowing variable name?


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: Reference column without knowing variable name?
Date   Tue, 2 Mar 2010 13:40:31 +0100

<> 

Doubling every third _numeric_ var in this example. If you want strings in there, kill the -has(type numeric)- option...

*************
ma drop _all
sysuse auto, clear

qui ds, has(type numeric)
forv i=1(3)`=_N'{
	loc newvars `newvars' `:word `i' of `r(varlist)''
}

foreach var of local newvars{
	replace `var'=2*`var'
}
*************

Careful, everything rides on your order of variables here!

HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] Im Auftrag von Andrew Wood
Gesendet: Dienstag, 2. März 2010 11:41
An: [email protected]
Betreff: st: Reference column without knowing variable name?

Hi everyone,

I am trying to create a STATA script that cycles through certain columns (variables) and perform a transformation. 

However, the datasets I am working with should only have every 3rd column (1,4,7,10...) transformed. This is ok but to make matters difficult, the datasets I am working with are VERY large and there is no pattern to the variable names.

I was wondering if anyone knew how to reference a column using a subscript in a loop, rather than a variable name (or use an integer to return the variable name of that column).

Thanks.

Andy

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index