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

st: RE: getting a list into a macro

From   "Newson, Roger B" <[email protected]>
To   <[email protected]>
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:

. 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


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 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
Tel: +44 (0)20 7352 8121 ext 3381
Fax: +44 (0)20 7351 8322
Email: [email protected] 
Web page:
Departmental Web page:

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

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Richard
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

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


*   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