Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
"Martin Weiss" <martin.weiss1@gmx.de> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
AW: st: finding the max of a variable and then using it |

Date |
Tue, 10 Aug 2010 17:10:46 +0200 |

<> " Re -summarize, meanonly-, also see NJC`s http://www.stata-journal.com/article.html?article=st0135"; Soon to be free, under the 3 year moving wall at the SJ, I guess... HTH Martin -----Ursprüngliche Nachricht----- Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Martin Weiss Gesendet: Dienstag, 10. August 2010 17:09 An: statalist@hsphsun2.harvard.edu Betreff: AW: st: finding the max of a variable and then using it <> Re -summarize, meanonly-, also see NJC`s http://www.stata-journal.com/article.html?article=st0135 HTH Martin -----Ursprüngliche Nachricht----- Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Maarten buis Gesendet: Dienstag, 10. August 2010 17:04 An: statalist@hsphsun2.harvard.edu Betreff: Re: st: finding the max of a variable and then using it --- On Tue, 10/8/10, Data Analytics Corp. wrote: > 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)) > > Of course this doesn't work since opp is a new variable > with as many observations as opp_price. I need a > scalar that I can then use in subsequent statements. > Can anyone help? The easiest way to do this is to store the maximum in a local macro (see -help macro-, also click through to the extended macro function, especially the display function may prove useful in your case). Also see the example below: *---------------- begin example ------------ sysuse auto sum mpg, meanonly local max = r(max) scatter price mpg, /// xline(`max') /// text(0 `max' "`max'", place(w)) *---------------- end example -------------- (For more on examples I sent to the Statalist see: http://www.maartenbuis.nl/example_faq ) Hope this helps, Maarten -------------------------- Maarten L. Buis Institut fuer Soziologie Universitaet Tuebingen Wilhelmstrasse 36 72074 Tuebingen Germany http://www.maartenbuis.nl -------------------------- * * 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/ * * 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/

**References**:**st: finding the max of a variable and then using it***From:*"Data Analytics Corp." <walt@dataanalyticscorp.com>

**Re: st: finding the max of a variable and then using it***From:*Maarten buis <maartenbuis@yahoo.co.uk>

**AW: st: finding the max of a variable and then using it***From:*"Martin Weiss" <martin.weiss1@gmx.de>

- Prev by Date:
**Re: st: finding the max of a variable and then using it** - Next by Date:
**st: RE: RE: RE: Replace missing values by 0** - Previous by thread:
**AW: st: finding the max of a variable and then using it** - Index(es):