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   "Riano, Juanita" <JRiano@imf.org>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: RE: Question for Statalist about "Creating a macro for files"
Date   Wed, 19 Apr 2006 13:40:45 -0400

Thank you very much both of you for the suggestions. 


---------------------------------------------
Juanita Riano
International Monetary Fund
Research Department
jriano@imf.org
phone 202-623-5437

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Ronnie
Babigumira
Sent: Wednesday, April 19, 2006 12:58 PM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: RE: Question for Statalist about "Creating a macro for
files"

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
> n.j.cox@durham.ac.uk
>  
>> 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/

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index