使用forvalues在Stata中循环下降值

Ale*_*xis 3 stata

所以这按预期工作:

. forvalues i = 1(1)3 {
  2. di `i'
  3. }
Run Code Online (Sandbox Code Playgroud)

1
2
3

而这不是:

. forvalues i = 3(1)1 {
  2. di `i'
  3. }
           <--- that's an empty line that returns from the above loop.
Run Code Online (Sandbox Code Playgroud)

如果我想生产

3
2
1
Run Code Online (Sandbox Code Playgroud)

我真的需要得到这个吗?

. forvalues i = 1(1)3 {
  2. di 3+1-`i'
  3. }
Run Code Online (Sandbox Code Playgroud)

为什么?

Nic*_*Cox 6

你的循环应该开始了

forv i = 3(-1)1 
Run Code Online (Sandbox Code Playgroud)

因为你的步骤-1不是1.