Statalist The Stata Listserver


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

st: Aggregate constant to scalar and local


From   Gawrich Stefan <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: Aggregate constant to scalar and local
Date   Fri, 13 Oct 2006 11:46:03 +0200

Hi statalisters,

maybe a silly question but is there a easier and more efficient solution to
the following task?
I didn't manage to find one even after some time of research...

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).

My solution: Calculate the sex-specific median via "egen" and afterwards
sort the data ascending and descending by sex, each time copying the first
medage observation to a scalar. 
bysort sex: egen medage = median(age)
gsort sex
scalar male_medage = medage
gsort -sex
scalar female_medage = medage
local male_medage = male_medage
local female_medage = female_medage

This seems not to be very smart because two times sorting is inefficient and
taking data from the first observation in this way easily lead to errors (if
there are changes in the stratum var like missing values or a third
category). 

So the question is if there are more convenient ways to calculate aggregate
constants and store them in locals.

Best wishes

Stefan









*
*   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