[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Proper usage of Macros stored in summarize

From   Thomas Speidel <>
Subject   st: Proper usage of Macros stored in summarize
Date   Tue, 02 Dec 2008 11:18:43 -0700

I am trying to use macros stored in the summarize command to flag outliers/influenetial observations if they fall outside of this range:
p25 - 2IQR <= var  <= p75 +2IQR

suppose I try to do this on the weight var from the auto.dta dataset (with a little modification):

sysuse auto, clear
set obs 75
replace weight = 8000 in 75
qui: summ  weight, d
gen weight_outlier=1 if (weight>`p(75)'+2*(`r(p75)'-`r(p25)') & (weight<.))
replace weight_outlier=1 if (weight<`p(25)'-2*(`r(p75)'-`r(p25)'))

If I was to do it by hand:
. di 3*2240-2*3670
. di 3*3670-2*2240
gen weight_outlier2=1 if weight>6530 & weight <.

There is something I am doing wrong in the first approach - read: poor macro programming :-) - but can't quite grasp what the problem is.

Thomas Speidel--
Thomas Speidel

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index