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

From   Sdfsdfsadfsf Sdfsdf <>
To   "" <>
Subject   st: How to use functions within variable names
Date   Wed, 17 Aug 2011 02:14:19 +0100 (BST)

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:

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