forval: Execute code in the datasets environment for all values of a...

Description Usage Arguments Value Examples

Description

Execute code in the datasets environment for all values of a vector, replacing a macro with the value in each iteration

Usage

1
forval(values, expr, macro = "%val")

Arguments

values

the vector of values to loop over. For example, specifying 1:5 would loop over integers from 1 to 5.

expr

a quoted expression (the experession must be enclosed in quotes) to evaluate in the loop which (presumably) uses the macro expression

macro

a word to replace in the quoted expression with the values we are looping over (default: "%val")

Value

returns NULL, invisibly

Examples

1
2
3
4
use(cars, clear=TRUE)
listif()
forval (2:4, "gen(speed%val, speed^%val)")
listif()

genvar documentation built on Jan. 21, 2020, 9:07 a.m.