Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Mergining horozontally excel files under a particular patern


From   Scott Merryman <scott.merryman@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Mergining horozontally excel files under a particular patern
Date   Tue, 3 Jul 2012 14:08:18 -0500

Something like:

clear
tempfile tmp
local j = 1
forv i = 39(-1)1 {
	import excel "C:\Users\scott.merryman\Desktop\Book1.xlsx",
sheet("Sheet`i'") firstrow clear
	if mod(`i',3) !=0 {
		qui merge 1:1 _n using `tmp', nogenerate
		save `tmp' ,replace
	}
	else {
		save `tmp', replace
	}
	if mod(`j', 3) == 0 {
		save gr`i', replace
		local j = 1
	}
	else {
		local j = `j' + 1
	}
}



Scott

On Mon, Jul 2, 2012 at 12:31 PM, sabbas gidarokostas
<sabbasgidarokostas@googlemail.com> wrote:
> I have an excel file that contains 39 sheets
> 1,2,3,4,5,6,7,8,9,10,11,….
>
> I want tfirst o merge sheet 3 with 2 and then merge the new sheet that
> results from this merging  with sheet 1. So 3+2+1
> Similarly, I want to merge first sheet 6 with 5 and then merge the new
> sheet that results from this merging with sheet 4. So. 6+5+4
> Similarly,  I want to merge first sheet 9 with 8 and then merge the
> new sheet that results from this merging with sheet 7. So,  9+8+7
> And so forth
> To be more specific,
> My goal is to merge horizontally all the data contained in sheet 3
> with the data contained in the matrix [C5 up to the C-end and C5 up to
> End-5] of Sheet 2. The outcome of this merging is then merged
> horizontally with the data contained in the matrix [C5 up to the C-end
> and C5 up to End-5] of Sheet 1
>
> Similarly, I  want to merge horizontally all the data contained in
> sheet 6 with the data contained in the matrix [C5 up to the C-end and
> C5 up to End-5] of Sheet 5. The outcome of this merging is then merged
> horizontally with the data contained in the matrix [C5 up to the C-end
> and C5 up to End-5] of Sheet 4
>
> and so forth.
>
> Is there any way to do this particular merging
>
> thanks

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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   |   Site index