I'm facing an issue with the putexcel command in Stata. In my
agent-based modeling project with a while loop, each iteration analyzes
the movements of agents in numerical units. I would like to export the
data generated in each iteration to a single Excel file, with each
iteration on a different sheet identified by its name. The challenge is
that I don't know how many values will be generated in each iteration,
making it impractical to use the putexcel command conventionally. I've
attempted to use a foreach loop to assign values to consecutive cells in
the corresponding sheet, but haven't achieved the desired results. Can
anyone suggest the correct approach to address this issue?
I present below an example of an option I have tried but it doesn't work
for me, since it only saves the values in cell A1 and keeps overwriting:
local i = 1
putexcel set "out_step.xlsx", sheet("Iteration`iteration'", replace)
modify
foreach value in p_1 {
putexcel A`i' = `value'
local i = `i' + 1
}
agent-based modeling project with a while loop, each iteration analyzes
the movements of agents in numerical units. I would like to export the
data generated in each iteration to a single Excel file, with each
iteration on a different sheet identified by its name. The challenge is
that I don't know how many values will be generated in each iteration,
making it impractical to use the putexcel command conventionally. I've
attempted to use a foreach loop to assign values to consecutive cells in
the corresponding sheet, but haven't achieved the desired results. Can
anyone suggest the correct approach to address this issue?
I present below an example of an option I have tried but it doesn't work
for me, since it only saves the values in cell A1 and keeps overwriting:
local i = 1
putexcel set "out_step.xlsx", sheet("Iteration`iteration'", replace)
modify
foreach value in p_1 {
putexcel A`i' = `value'
local i = `i' + 1
}
Comment