[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: Aggregate constant to scalar and local
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)
scalar male_medage = medage
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
So the question is if there are more convenient ways to calculate aggregate
constants and store them in locals.
* For searches and help try: