Statalist The Stata Listserver


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

st: RE: RE: RE: Using "outsheet" and foreach again


From   "Rajesh Tharyan" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: RE: Using "outsheet" and foreach again
Date   Thu, 20 Apr 2006 18:26:31 +0100

Sorry a slight correction to the code

foreach file in decilenopur decilenosell { 
use "`file'"
outsheet using bra`file'.csv, comma replace 
clear
}

You need to use the "file".. or it will just create two files which are
empty..

So the logic is 
for each of the files..

1. You use it i.e open that file
2. Save it as csv file with bra prefix
3. Clear that file from memory
4. use the next file and do the whole process again

Regrda
rajesh

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Riano, Juanita
Sent: 20 April 2006 16:41
To: [email protected]
Subject: st: RE: RE: Using "outsheet" and foreach again

Thank you Rajesh and Jennifer for your help!

Best

Juanita 


---------------------------------------------
Juanita Riano
International Monetary Fund
Research Department
[email protected]
phone 202-623-5437

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Rajesh
Tharyan
Sent: Thursday, April 20, 2006 11:38 AM
To: [email protected]
Subject: st: RE: Using "outsheet" and foreach again

Hi,

This should work

foreach file in decilenopur decilenosell { outsheet using bra`file'.xls,
comma replace }

Here I tried using my own files decilenopur and decilenosell and it does
work..

Regards
rajesh


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Riano,
Juanita
Sent: 19 April 2006 19:19
To: [email protected]
Subject: st: Using "outsheet" and foreach again

Dear all, 

I am still facing problems with the outsheet and foreach commands. 

Nick gave me a good solution except that my outsheet files don't use
numbers. My inputs are 15 datasets labeled as oilgs.dta chmcl.dta ... 
And I need to have 15 excel files with the same name plus the prefix bra
(ie  braoilgs.xls  brachcml.xls....)

This is what I have so far:

foreach x in  oilgs chmcl bresr indgs fdbev perhh hlthc rtail media
trles telcm utils banks insur finsv { foreach file in oilgs chmcl bresr
indgs fdbev perhh hlthc rtail media trles telcm utils banks insur finsv
{ use `file', clear outsheet using bra`x'.xls , replace } }

However this keeps saving the first dataset "oilgs.dta"  under  15
different names braoilgs.xls brachmcl.xls 

I'd appreciate your suggestions 

Thank you!

 

---------------------------------------------
Juanita Riano
International Monetary Fund
Research Department
[email protected]
phone 202-623-5437


*
*   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/

*
*   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