Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: Question for Statalist about "Creating a macro for files"


From   Ronnie Babigumira <[email protected]>
To   [email protected]
Subject   Re: st: RE: Question for Statalist about "Creating a macro for files"
Date   Wed, 19 Apr 2006 18:58:12 +0200

Had not seen this when I sent my -forval- solution. I agree with Nick. One small comment, if you decide to continue with the loop, having all .dta files with the same "prefix" eg data1, data2 would make it easy for you to relate them to the bras in excel as they would be a 1 to 1 match in name (data1 = bra1)



Nick Cox wrote:

-outsheet- will only support output using one file, so your -outsheet- command is illegal.
I count three .dta files here, and three .xls files.
I guess that you want the equivalent of
use oilgs, clear outsheet using bra1.xls
use data2, clear outsheet using bra2.xls
use data3, clear outsheet using bra3.xls

Using -foreach- is not going to help you much here. There is too much irregular detail that is not reducible.
You could do this.
local i = 1 foreach file in oilgs data2 data3 { use `file', clear outsheet using bra`i'.xls local ++i }
but that replaces 6 lines with 6. I could reduce the code to 5 lines, but at the cost of some simplicity.
As said, the loop is not much simpler than the code without a loop.

If you do have an example with 5 files, the loop is going to help you a bit more.
Nick [email protected]
I am trying to use the foreach command to "outsheet" five statafiles
into 5 excel files but don't know how to create the two lists.
So far I have this...

#delimit; foreach file in oilgs.dta data2.dta data3.dta {;
outsheet using bra1.xls bra2.xls bra3.xls , replace;
};

But it doesn't recognize the list of xls files

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index