Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Aggregate constant to scalar and local


From   Ulrich Kohler <[email protected]>
To   [email protected]
Subject   Re: st: Aggregate constant to scalar and local
Date   Fri, 13 Oct 2006 12:59:37 +0200

Gawrich Stefan wrote:
> I want to obtain aggregate values (e.g. median age by sex) from an
> individual data set and generate locals out of them (to show the values in
> a textbox in a graph).

Others have proposed different solutions. Here is one that tries to be fast:

. _pctile age if sex==1
. local female_medage = r(r1)
. _pctile age if sex==2
. local female_medage = r(r1)

or, slighly more general:

. levelsof sex, local(K)
. foreach k of local K {
.	_pctile age if sex == `k'
.	local medage`k' = `r1'
. }

(This produces local macros medage1 and medage2)


The major lesson to be learned from this and the other solutions is to work 
with "saved results" (See -help return-, or chapter 4 in Kohler/Kreuter "Data 
Analysis Using Stata") 

hope this helps
Uli

-- 
[email protected]
+49 (030) 25491-361
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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