Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Three-way table export


From   Eric Booth <[email protected]>
To   [email protected]
Subject   Re: st: Three-way table export
Date   Thu, 29 Aug 2013 05:00:13 -0500

<>

One way to export -table- output is via -logout- from SSC.

Another thing I've been doing a lot of lately is toying with wrappers for -tabout- (also from SSC) to build large/complex tables in excel, so here's one way to use something like that to build your table:



***********
**will contain overall table:
clear
sa overall.dta, replace emptyok

**fake data
 sysuse auto, clear
 
 **example like the one you describe:
 table mpg  rep78  if rep78 !=., c(p25 price  median price  p75 price) format(%12.1f) center
 

**using tabout to build your table:
forval n = 1/3 {

  if `n'==1 loc j p25
  if `n'==2 loc j median
  if `n'==3 loc j p75
  
 tabout mpg  rep78  if rep78 !=. using test`n'.xls, ///
	sum replace c(`j' price  ) f(12c) 

preserve
 insheet using test`n'.xls, clear nonames
	**assign a row #
	drop in 1
	drop in 2
	g i = `n'
	if `n' != 1 drop in 1
	if `n' == 1 g overall =1 if index(v1, "Mil")
tempfile d`n'
sa `d`n''
append using overall.dta
sa overall.dta, replace
restore
	}
**cleanup**	
u overall.dta, clear
sort overall v1 i 
order v1 i
drop overall
replace i = . if index(v1, "Mil")
lab def i 1 "p25" 2 "median" 3 "p75", modify
lab val i i //just something I prefer
**export the table	
export excel using overall.xlsx, replace
***************

- Eric


On Aug 29, 2013, at 4:30 AM, arosella <[email protected]> wrote:

> I'm using Stata 12.1 on W7.
> I've tried the following command using -table-
> 
> . table month  Age_C Gender if Age_C !=., c(p25 MAI  median MAI  p75 MAI) format(%12.1f) center
> 
> (MAI is the Mediterranean Adequacy Index)
> 
> and it works fine. Now I'd want to export the table to an other document but I'd want to do it automatically.
> -outreg2- from ssc may be a solution and I've tried it but not was able to build a three way table with
> p25, p50 and p75 of a fourth variable (MAI) as a content of the cell.
> Can someone to help me?
> Thank you in advance
> 
> Alberto R. Osella
> Laboratorio di Epidemiologia e Biostatistica
> IRCCS Saverio de Bellis
> Via Turi, 27
> 70013 Castellana Grotte (BA)
> Italia
> tel: +39 0804994655
> fax: +39 0804994650
> e-mail: [email protected]
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index