Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[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 <nshephard@gmail.com>
To   statalist@hsphsun2.harvard.edu
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.
<walt@dataanalyticscorp.com> 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 - nshephard@gmail.com
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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index