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: How to use functions within variable names


From   Sdfsdfsadfsf Sdfsdf <jagfish101@yahoo.de>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: How to use functions within variable names
Date   Wed, 17 Aug 2011 02:14:19 +0100 (BST)

Hello,
is it possible to use the result of a function or mathematical operation as a part of a variable name?

Here is a simple example what I want to do


forvalue i=1(1)2 {
rename r`i'= r[`i'-1]    // Instead of the operation in the squared brackets there should be the result eg.0 for 1-1
}



or an more accurate example with variables


forvalue i=1(1)100 {
replace b_`i'= a[c+`i']
}

c is a variable with integer values
The result of c+`i' determines the variable from which the value of b_`i'is taken from


eg    `i'=3; c=7;
        b_3 =a10 

*
*   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