Statalist


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

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


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   AW: st: SV: AW: Output from tabulate to a matrix
Date   Thu, 21 Jan 2010 16:51:34 +0100

<> 


Tomas may also want to read up on this issue in manual [U], section 18.3.9.,
where the "from the inside" evaluation of nested -macro-s is explained.



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von William Gould,
StataCorp LP
Gesendet: Donnerstag, 21. Januar 2010 16:36
An: [email protected]
Betreff: Re: st: SV: AW: Output from tabulate to a matrix

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/


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