forvalue是Stata自带命令,不需要安装。
直接在命令行窗口执行
help forvalue
就可以看到对应的帮助的内容
[P] forvalues -- Loop over consecutive values
(View complete PDF manual entry)
Syntax
forvalues lname = range {
Stata commands referring to `lname'
}
where range is
#1(#d)#2 meaning #1 to #2 in steps of #d
#1/#2 meaning #1 to #2 in steps of 1
#1 #t to #2 meaning #1 to #2 in steps of #t - #1
#1 #t : #2 meaning #1 to #2 in steps of #t - #1
The loop is executed as long as calculated values of `lname' are < #2, assuming that #d > 0.
Braces must be specified with forvalues, and
1. the open brace must appear on the same line as forvalues;
2. nothing may follow the open brace except, of course, comments; the first command to be executed must appear on a new line;
3. the close brace must appear on a line by itself.
Description
forvalues repeatedly sets local macro lname to each element of range and executes the commands enclosed in braces. The loop is executed zero or more times.
forvalues is the fastest way to execute a block of code for different numeric values of lname.