Hi there I am using Stata/BE 17,
I am having issues displaying the contents of a global macro that I generate using a loop. Instead, what displays is the last reference from my last global references in the loop. The loop is working and I can successfully access the contents of the global macro if I type display "$full macro name" after the loop is completed.
Example:
My results are as follows from the above loop:
However, if I type any of the potential combinations for the lists I created, I can obtain the correct results:
I would like to loop through a factor analysis for each typexwing combination using the created macro lists, but when I attempt to I get the error related to the incorrect display (e.g., variable w2 not found). The full code would look something like:
but results in:
I have sleuthed and sleuthed, but I may be using incorrect terminology since I am new to Stata. Any help is greatly appreciated. Thanks!
I am having issues displaying the contents of a global macro that I generate using a loop. Instead, what displays is the last reference from my last global references in the loop. The loop is working and I can successfully access the contents of the global macro if I type display "$full macro name" after the loop is completed.
Example:
Code:
/*creating global macros for following foreach loop*/ global types "t1 t2 t3 t4 t5 t6 t7 t8 t9" global wings_t1 "w2 w9" global wings_t2 "w1 w3" global wings_t3 "w2 w4" global wings_t4 "w3 w5" global wings_t5 "w4 w6" global wings_t6 "w5 w7" global wings_t7 "w6 w8" global wings_t8 "w7 w9" global wings_t9 "w8 w1" /*loop and create global for each type by wing*/ foreach t of global types { foreach w of global wings_`t' { global `t'_`w' "`t'_`w'_1 `t'_`w'_2 `t'_`w'_3 `t'_`w'_4 `t'_`w'_5 `t'_`w'_6 `t'_`w'_7 `t'_`w'_8" display "$`t'_`w'" } }
Code:
w2 w9 w1 w3 w2 w4 w3 w5 w4 w6 w5 w7 w6 w8 w7 w9 w8 w1
Code:
display "$t9_w8" t9_w8_1 t9_w8_2 t9_w8_3 t9_w8_4 t9_w8_5 t9_w8_6 t9_w8_7 t9_w8_8
Code:
foreach t of global types { foreach w of global wings_`t' { global `t'_`w' "`t'_`w'_1 `t'_`w'_2 `t'_`w'_3 `t'_`w'_4 `t'_`w'_5 `t'_`w'_6 `t'_`w'_7 `t'_`w'_8" display "$`t'_`w'" factor $`t'_`w', mineigen(1) blanks(.30) ipf rotate, oblimin(0) kaiser blanks(.30) screeplot, name(`t'_`w') title(`t'_`w') sortl } }
Code:
. foreach t of global types { 2. foreach w of global wings_`t' { 3. global `t'_`w' "`t'_`w'_1 `t'_`w'_2 `t'_`w'_3 `t'_`w'_4 `t'_`w'_5 `t'_`w'_6 `t'_`w'_7 `t'_`w'_8" 4. display "$`t'_`w'" 5. factor $`t'_`w', mineigen(1) blanks(.30) ipf 6. rotate, oblimin(0) kaiser blanks(.30) 7. screeplot, name(`t'_`w') title(`t'_`w') 8. sortl 9. } 10. } w2 variable w2 not found r(111);
Comment