Statalist


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

st: RE: getting a list into a macro


From   "Newson, Roger B" <r.newson@imperial.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: getting a list into a macro
Date   Fri, 26 Sep 2008 20:54:55 +0100

In the auto data, I might proceed as follows:

**** BEGINNING OF Stata RESULTS - CUT HERE
. sysuse auto, clear
(1978 Automobile Data)

. local makes ""

. local nmake=_N

. forv i1=1(1)`nmake' {
  2. local makecur=make[`i1']
  3. local makes `"`makes' `makecur'"'
  4. }

. disp `"`makes'"'
 AMC Concord AMC Pacer AMC Spirit Buick Century Buick Electra Buick
LeSabre Buick Opel Buick Regal Buick Riviera Buick Skylark Cad. Deville
Cad. Eldorado Cad. Sevill
> e Chev. Chevette Chev. Impala Chev. Malibu Chev. Monte Carlo Chev.
Monza Chev. Nova Dodge Colt Dodge Diplomat Dodge Magnum Dodge St. Regis
Ford Fiesta Ford Mustang
>  Linc. Continental Linc. Mark V Linc. Versailles Merc. Bobcat Merc.
Cougar Merc. Marquis Merc. Monarch Merc. XR-7 Merc. Zephyr Olds 98 Olds
Cutl Supr Olds Cutlass 
> Olds Delta 88 Olds Omega Olds Starfire Olds Toronado Plym. Arrow Plym.
Champ Plym. Horizon Plym. Sapporo Plym. Volare Pont. Catalina Pont.
Firebird Pont. Grand Pri
> x Pont. Le Mans Pont. Phoenix Pont. Sunbird Audi 5000 Audi Fox BMW
320i Datsun 200 Datsun 210 Datsun 510 Datsun 810 Fiat Strada Honda
Accord Honda Civic Mazda GLC 
> Peugeot 604 Renault Le Car Subaru Toyota Celica Toyota Corolla Toyota
Corona VW Dasher VW Diesel VW Rabbit VW Scirocco Volvo 260

. 
**** END OF Stata RESULTS - CUT HERE

HOWEVER, if I thought that the variable -make- might contain irregular
characters, such as quotes, then I might replace the command

local makes `"`makes' `makecur'"'

with the Mata invocation

mata: st_local("makes",st_local("makes")+" "+st_local("makecur"))

and replace the command

disp `"`makes'"'

with the Mata invocation

mata: printf(st_local("makes")+"\n")

I hope this helps.

Best wishes

Roger


Roger B Newson BSc MSc DPhil
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
UNITED KINGDOM
Tel: +44 (0)20 7352 8121 ext 3381
Fax: +44 (0)20 7351 8322
Email: r.newson@imperial.ac.uk 
Web page: www.imperial.ac.uk/nhli/r.newson/
Departmental Web page:
http://www1.imperial.ac.uk/medicine/about/divisions/nhli/respiration/pop
genetics/reph/

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

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Richard
Goldstein
Sent: 26 September 2008 20:29
To: statalist
Subject: st: getting a list into a macro

I have a string variable that is 6 characters long -- about 100
observations

I want to get each value into one long macro with spaces between each 
value -- how can I do that?

Thanks,

Rich
*
*   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/



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