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


From   Sdfsdfsadfsf Sdfsdf <[email protected]>
To   "[email protected]" <[email protected]>
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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index