Statalist The Stata Listserver

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

Re: st: RE: Save results as a data file

From   Ronnie Babigumira <[email protected]>
To   [email protected]
Subject   Re: st: RE: Save results as a data file
Date   Sun, 17 Sep 2006 15:08:42 +0200


I initially proposed a -collapse- for this but then I saw Svend's suggestion of -contract- which was a neat oneliner. However, like collapse, it would destroy the data in the memory so I suggested that a preserve before contracting or collapsing .. (Shihe has privately asked about keeping the data in memory)

-xcontract- on the other hand offers the option of saving the result in a dataset leaving the data in memory intact and that is just perfect. I think Shihe will like it



Newson, Roger B wrote:

I think what you are looking for might be the -xcontract- utility,
downloadable from SSC using the -ssc- command. If you install this and

xcontract X, saving(myresults.dta, replace)
then you will create a dataset in myresults.dta with 1 observation per
value of X and variables X, _freq and _percent, containing the X-value,
frequency and percent, respectively.

I hope this helps.


Roger Newson
Lecturer in Medical Statistics
Respiratory Epidemiology and Public Health Group
National Heart and Lung Institute
Imperial College London
Royal Brompton campus
Room 33, Emmanuel Kaye Building
1B Manresa Road
London SW3 6LR
Tel: +44 (0)20 7352 8121 ext 3381
Fax: +44 (0)20 7351 8322
Email: [email protected]

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

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Fan, Shihe
Sent: 15 September 2006 21:16
To: [email protected]
Subject: st: Save results as a data file

Hi, everyone,

As a new user, could any one show me how to save the results as a data
file so that I can reuse it.
Say, I have a variable (x) with many levels in a file. I want to get
the total count of each level in a file.
The codes;

Sort x;
By x: count;

Will produce the results on the screen, but I want it in a file like:

1 5
2 10

Thank you

Shihe Fan
Office of the MOH
Public Health Division
Suite 300, 10216 - 124 Street
Edmonton AB T5N 4A3
Phone:(780) 413-7742
Fax: (780) 413-7950
[email protected]

* For searches and help try:

* For searches and help try:

*   For searches and help try:

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