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: finding the max of a variable and then using it


From   Neil Shephard <[email protected]>
To   [email protected]
Subject   Re: st: finding the max of a variable and then using it
Date   Tue, 10 Aug 2010 14:47:21 +0000

On Tue, Aug 10, 2010 at 2:43 PM, Data Analytics Corp.
<[email protected]> wrote:
> Hi,
>
> I have a data set with a variable called opp_price.  I'd like to find the
> maximum value for opp_price (I would imagine I'd use
>
> egen opp = max(opp_price)
>
> or something like this, but then use this single value in subsequent
> graphing statements like the following:
>
> xline(opp, lwidth(thin))
> text(0.0 238 "OPP: $opp", place(w))

Well as you've clocled the above doesn't set opp_price as a global
macro, which is how you are trying to refer to it in your graph call.
And as you write you need to use a scalar, and the key is to save it
in a local macro


qui sum opp
local max_opp = r(max)
 xline(opp, lwidth(thin)) \\
 text(0.0 238 "OPP: `max_opp'", place(w))

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