Hi everyone!
I’m trying to use a global of globals in a loop. Let me clarify: I have three global macros - "a", "b", and "c" - each containing a list of variables, for example: global a "1 2 3", global b "4 5 6 7", and global c "8 9". I need to run some regressions for each group of variables, so I’d like to create a new global that contains the names of these three original globals, like global outcomes "a b c". This would allow me to loop through each regression for every group of variables.
Here is the working code I currently have:
global a "1 2 3"
global b "4 5 6 7"
global c "8 9"
/*Tab 1: a */
eststo clear
foreach var in $a {
mainreg `var'
}
esttab using "$tex_maintables\rc1\a", $options
/*Tab 2: b */
eststo clear
foreach var in $b{
mainreg `var'
}
esttab using "$tex_maintables\rc1\b", $options
/* Tab 3: c*/
eststo clear
foreach var in $c{
mainreg `var'
}
esttab using "$tex_maintables\rc1\c", $options
And here is how I attempted to shorten it using a loop, but it does not work properly:
global a "1 2 3"
global b "4 5 6 7"
global c "8 9"
global outcome "a b c"
eststo clear
foreach group in $outcome {
foreach var in $`group' {
mainreg `var'
esttab using "$tex_maintables\rc1\$outcome", $options
}
}
My issue is how to handle globals within a global.
I hope my question is clear, but if you need further clarification, please ask. Thank you for your time!
I’m trying to use a global of globals in a loop. Let me clarify: I have three global macros - "a", "b", and "c" - each containing a list of variables, for example: global a "1 2 3", global b "4 5 6 7", and global c "8 9". I need to run some regressions for each group of variables, so I’d like to create a new global that contains the names of these three original globals, like global outcomes "a b c". This would allow me to loop through each regression for every group of variables.
Here is the working code I currently have:
global a "1 2 3"
global b "4 5 6 7"
global c "8 9"
/*Tab 1: a */
eststo clear
foreach var in $a {
mainreg `var'
}
esttab using "$tex_maintables\rc1\a", $options
/*Tab 2: b */
eststo clear
foreach var in $b{
mainreg `var'
}
esttab using "$tex_maintables\rc1\b", $options
/* Tab 3: c*/
eststo clear
foreach var in $c{
mainreg `var'
}
esttab using "$tex_maintables\rc1\c", $options
And here is how I attempted to shorten it using a loop, but it does not work properly:
global a "1 2 3"
global b "4 5 6 7"
global c "8 9"
global outcome "a b c"
eststo clear
foreach group in $outcome {
foreach var in $`group' {
mainreg `var'
esttab using "$tex_maintables\rc1\$outcome", $options
}
}
My issue is how to handle globals within a global.
I hope my question is clear, but if you need further clarification, please ask. Thank you for your time!
Comment