This will produce a smaller data set consisting of the medians by
group of 30 in the original dataset
tempfile medians
local myvars "var1-var10"
gen id=_n
gen group=int((id-1)/30)
forvalues i=1/10 {
local j: word `i' of `myvars'
egen median`j'=median(`j'), by(group)
}
keep group median*
egen u=tag(_all)
keep if u==1
save "`medians'", replace
On 5/17/07, Morrison Hodges <[email protected]> wrote:
I have a dataset of 10 variables and 5000 observations. I need to calculate
the median of each variable in groups of 30 observations, i.e., the median
of each variable in observations 1-30, then the median for 31-60, then
61-90, etc. I know I can get the median from the p50 value of -summarize-,
but I'm not sure how to obtain consecutive segments of 30 observations each
to perform -summarize- on. Can anyone help?
Thanks, Morry Hodges
Morrison Hodges, MD
Professor Emeritus of Medicine
University of Minnesota
Senior Investigator
Minneapolis Heart Institute Foundation
612-863-3766
612-863-2490 (fax)
612-889-7695 (mobile)
[email protected]
http://www.mplsheartfoundation.org/
The reasonable man adapts himself to the world; the
unreasonable man persists in trying to adapt the world
to himself. Therefore all progress depends on the
unreasonable man.
George Bernard Shaw
*
* 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/
*
* 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/