Search code examples
statamediansummarize

Calculate Median after Summarize with detail in Stata


The summarize command creates various scalars in Stata. For instance, one can store the mean or min/max values through gen mean=r(mean)afterwards. It is also possible to get more sophisticated measures via the summarize varname, detailoption. Through this, one also obtains the median in form of the 50% percentile.

My goal is to store the median. Is there a corresponding scalar?

Where can I obtain information on stored scalars after standard operations like summarize? As far as I can see they are not listed in the Stata manuals.


Solution

  • After each command, one can find out where the results are saved through ereturn list or return list.

    In the case of summarize varname, detail the median can be obtained through r(p50).

    summarize varname, detail
    return list
    local var_median = r(p50)