Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: tabulate results -> Excel

From   Roger Newson <[email protected]>
To   [email protected]
Subject   Re: st: tabulate results -> Excel
Date   Tue, 23 Nov 2004 19:15:10 +0000

At 17:00 23/11/2004, Kit Baum wrote:
Posting for my colleague Peter Gottschalk:

I have a bunch of crosstabs (from tabulate) that need to be turned into tables in an excel spreadsheet. Is there a way of outputing the contents of tabulate to a file?

A possibility is to use -xcontract-, downloadable from SSC, instead of -tabulate-. If you type

tempfile tf1 tf2 tf3
xcontract y, saving(`tf1', replace) freq(rowfreq) percent(rowpct)
xcontract x, saving(`tf2', replace) freq(colfreq) percent(colpct)
xcontract x y, saving(`tf3', replace) freq(cellfreq) percent(cellpct)
use `tf3', clear
merge x using `tf2'
sort y x
merge y using `tf1'
sort x y

then you should have a dataset in memory with 1 observation per cell and variables
x, y, rowfreq, rowpct, colfreq, colpct, cellfreq and cellpct, containing the x-values and y-values and also the row, column and cell frequencies and percents. This dataset can be further reprocessed using -reshape-, if Peter wants a dataset with 1 observation per row instead of a dataset with 1 observation per cell. The final dataset can be output to a text spreadsheet file using the official Stata command -outsheet-.

I hope this helps.

Best wishes


Roger Newson
Lecturer in Medical Statistics
Department of Public Health Sciences
King's College London
5th Floor, Capital House
42 Weston Street
London SE1 3QD
United Kingdom

Tel: 020 7848 6648 International +44 20 7848 6648
Fax: 020 7848 6620 International +44 20 7848 6620
or 020 7848 6605 International +44 20 7848 6605
Email: [email protected]

Opinions expressed are those of the author, not the institution.

* For searches and help try:

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