Statalist


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

Re: st: SV: AW: Output from tabulate to a matrix


From   [email protected] (William Gould, StataCorp LP)
To   [email protected]
Subject   Re: st: SV: AW: Output from tabulate to a matrix
Date   Thu, 21 Jan 2010 09:36:10 -0600

Tomas Lind <[email protected]> asked, 

> Is it possible to store names in a matrix for example "east",
> "west", "north", "south" and then display the one that I want, for
> example the 3:rd element "north"?

and Martin Weiss <[email protected]> replied, 

> Could well be as easy as
> 
> *************
> local mynames "nameone nametwo namethree namefour namefive"
> 
> token `mynames'
> 
> local mycount: word count `mynames'
> 
> forv i=1/`mycount'{
>         //-lincom- statement goes here
>         di in r "``i''"
> }
> *************

and that seemed to be a hit because Tomas then replied, "Perfect."

Given that, here's another, related solution.  Start by defining 
separate macros for each member of the list:

        . local name1 "north"
        . local name2 "south"
        . local name3 "east"
        . local name4 "west"

Now say we want to display the `i'th name.  We can type:

        . display "`name`i''

For instance, if `i' contained 3, 

        . local i = 3 
        . display "`name`i''"
        east

That works because `name`i'' first expands to `name3' (Stata goes inside 
and substitutes the contents of i for `i'), and then `name3' expands to 
east in the usual way. 

-- Bill
[email protected]
*
*   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