简体   繁体   English

将Excel Loop放入Stata

[英]Put Excel Loop in Stata

I am trying to extract values incorporated in a Forvalues "Loop" from Stata to Excel. 我正在尝试从Stata提取包含在Forvalues“循环”中的值到Excel。

forvalues i = 20(5)40 {

forvalues x = 0(5)10 {
local xlsrow = 2
putexcel A`xlsrow'=("`i'_`x'") using results, sheet("individuals") modify

local xlsrow = `xlsrow'+4               
}
}

In the first stage I just want to write the different combinations of the variables i & x into the column A. Unfortunately, the only result I receive is the last combination 40_10 in row A2. 在第一阶段,我只想将变量i和x的不同组合写入列A。不幸的是,我收到的唯一结果是行A2中的最后一个组合40_10。 So somehow, I must have a problem in the local xlsrow, but I am unable to figure it out. 因此,无论如何,我在本地xlsrow中肯定有问题,但是我无法弄清楚。 Help is highly appreciated! 非常感谢您的帮助!

Not sure if this is exactly what you have in mind, but this will create data in cells in A2:A16 that look like this: 不知道这是否正是您要记住的内容,但这会在A2:A16的单元格中创建数据,如下所示:

20_0
20_5
20_10
25_0
...
40_10

Stata code: Stata代码:

local xlsrow = 2
putexcel set results, sheet("individuals") replace

forvalues i = 20(5)40 {
    forvalues x = 0(5)10 {
        putexcel A`xlsrow'=("`i'_`x'")
        local xlsrow = `xlsrow'+1               
    }
}

!open results.xlsx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM