I just started working with Stata and I couldn't figure out the following.
How can I loop over the lists of Excel sheets and the indices. This works fine now.
clear all set more off local mysheets 1996 2000 2003 2007 2008 2010 local indices index1 index2 index3 foreach sheetname of local mysheets { import excel "C:\stata\Data.xls", sheet(`sheetname') firstrow clear foreach index of local indices{ tobit theta index, ll(0) ul(1) outreg using "C:\stata\results.doc" , `append' local append "append" } }
locals are named differently:mysheetsvs.mysheet'append'before you define it (note the incorrect use of'; I can't figure out how to get SO to allow me to use the proper backtick in this context). And it's not clear why you would define it in the first place (in this context, at least).sheetnameto `sheetname'and it works.