<>
-display- may indeed be your best friend in this exercise...
*************
sysuse auto, clear
forvalues i = 1/`=_N'{
disp "Car #: `i': " _n/*
*/ make[`i'] _col(18) " with mpg: " mpg[`i'] _n/*
*/ "which is a `:lab origin `=foreign[`i']'' car" _n
}
*************
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Dick Campbell
Gesendet: Sonntag, 21. Juni 2009 17:46
An: statalist-hsphsun2.harvard.edu
Betreff: st: Listing data in a user-defined layout
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/
*
* 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/