Statalist


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

st: Listing data in a user-defined layout


From   Dick Campbell <[email protected]>
To   "statalist-hsphsun2.harvard.edu" <[email protected]>
Subject   st: Listing data in a user-defined layout
Date   Sun, 21 Jun 2009 10:45:34 -0500

I am posting this note a second time because I think
the list manager may have rejected the first version.
My apologies if this appears twice.

I have a data set on a number of firms chosen for a survey sample.
I want a list of the cases, formatted in a particular way. For
example, I want the firm's name and the number of employees
on line 1, the address on line 2 and the phone number on line 3.
Of course I can do this in other software used to produce mailing
labels or whatever, but I want to do it in Stata.

I can see how -display- can do this for me, but I am puzzled as to
the best  way to loop over the cases in a data set. I would think that
-forvalues- using _n as a subscript would work and the following
little do file does work, but note that it requires me to explicitly subscript
each variable.

local max = _N
forvalues i = 1/`max'{
display make[`i']  "  " mpg[`i']
}

produces

AMC Concord  22
AMC Pacer  17
AMC Spirit  22
Buick Century  20
. . . .
. . . .
VW Scirocco  25
Volvo 260  17

I can see how I can make this list prettier by moving mpg to a fixed position etc,
but I wonder if there isn't an easier way to loop through a set of
observations displaying data in a user-defined layout.

I should add that I have done a little homework here, but -findit- "list" or "display"
generates dozens of entries.

Richard T. Campbell
Institute for Health Research and Policy
University of Illinois at Chicago, M/C 275





*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index