I want to run regressions using one variable at a time and store results for each of those. The following code does exactly that.
sysuse auto
local var mpg rep78 headroom trunk weight
estimates clear
foreach v of varlist `var' {
regress price `v'
estimates store m_`v'
}
esttab m_*

However, instead of saving the results with variable names (m_'v') I wanted to use a numeric identifier for the results (e.g., m_1, m_2). When I use the following code I am getting extra models for the first variable in the list (mpg).

sysuse auto
local var mpg rep78 headroom trunk weight
estimates clear
local n : word count `var'
forvalues i = 1/`n' {
foreach v of varlist `var'{
regress price `v'
estimates store m_`i'
local ++i
}
}

esttab m_*
So, instead of getting only five outputs I am now getting nine outputs. 'n' is five, and for the first variable 'mpg' I am getting five outputs. I am surely doing something pretty silly. Any suggestions?

Thank you for your help.

Sincerely,
Manish

related posts

https://www.statalist.org/forums/for...un-regressions
https://www.statalist.org/forums/for...oop-regression