Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: how to input a numlist into a matrix


From   Roger Newson <roger.newson@kcl.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: how to input a numlist into a matrix
Date   Fri, 06 Sep 2002 17:39:24 +0100

At 12:16 06/09/02 -0400, Radu Ban wrote:
Dear all,

For a program, I want to input a numerical list into a matrix.
I want to store the list in a local so that I can modify it easily. Namely,
I'm looking at something like:

    local nlist "10(5)90 91(1)99 99.1(0.1)99.9 99.91(0.01)99.99"

but then, if I use:

    tokenize "`nlist'"

and try to see if i'm doing the right thing by:

    di `1'

i get an invalid syntax error.
Furthermore, I'm not sure how to get the size of the numlist so that I can
initialize my matrix with:

    matrix A = J(1, size_of_numlist, 0)

Can anyone give me some suggestions?
Radu needs to use the Stata command -numlist- (type -help nlist- in Stata). -numlist- expands an abbreviated numerical list like Radu's (with brackets) into a full numerical list, which is saved in the macro result -r(numlist)-, which can be handled by -tokenize- or -gettoken-. The following sequence demonstrates the -numlist- command:

. numlist "1(5)100"

. retu list

macros:
r(numlist) : "1 6 11 16 21 26 31 36 41 46 51 56 61 66 71 76 81 86 91 96"

. local nl1 "`r(numlist)'"

. disp "`nl1'"
1 6 11 16 21 26 31 36 41 46 51 56 61 66 71 76 81 86 91 96

To get the size of this numlist, type

local nnum:word count `nl1'

and the macro -nnum- will contain the size of the full numlist. See -[P] macro- for extended macro functions.

I hope this helps.

Roger


--
Roger Newson
Lecturer in Medical Statistics
Department of Public Health Sciences
King's College London
5th Floor, Capital House
42 Weston Street
London SE1 3QD
United Kingdom

Tel: 020 7848 6648 International +44 20 7848 6648
Fax: 020 7848 6620 International +44 20 7848 6620
or 020 7848 6605 International +44 20 7848 6605
Email: roger.newson@kcl.ac.uk

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

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* 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