Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Writing a value from a variable into a macro


From   Neil Shephard <[email protected]>
To   [email protected]
Subject   Re: st: Writing a value from a variable into a macro
Date   Fri, 24 Sep 2010 12:41:43 +0000

On Fri, Sep 24, 2010 at 12:31 PM, Palan, Stefan
([email protected]) <[email protected]> wrote:
> Hi everybody,
>
> I would like to write a specific value of a variable in my dataset into a macro. Assume I have a dataset with the two variables "number" and "text". They contain observations like (1, "one"), (2, "two"), (3, "three"), etc. Now I would like to write a specific value into a local macro. For example, I might be looking for the text that goes with the observation with number==2, and would like to assign that value to a local macro. Very amateurishly, I was looking for code similar to the following:
>
> local v=text if number==2

Assuming there is only ever one value of "text" that corresponds to
each "number" you can...

levelsof text if(number == 2), local(t)
di "`t'"

Neil

-- 
"One should as a rule, respect public opinion in so far as is
necessary to avoid starvation and to keep out of prison, but anything
that goes beyond this is voluntary submission to an unnecessary
tyranny, and is likely to interfere with happiness in all kinds of
ways..." - Bertrand Russell

Email - [email protected]
Website - http://slack.ser.man.ac.uk/
Photos - http://www.flickr.com/photos/slackline/

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index