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: Reference column without knowing variable name?


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
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: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Andrew Wood
Gesendet: Dienstag, 2. März 2010 11:41
An: statalist@hsphsun2.harvard.edu
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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index