Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Keep/Drop Observations for Top/Bottom X%


From   Maarten Buis <[email protected]>
To   [email protected]
Subject   Re: st: Keep/Drop Observations for Top/Bottom X%
Date   Thu, 11 Oct 2012 12:15:18 +0200

On Thu, Oct 11, 2012 at 11:59 AM, Lisa Wang  wrote:
> Thank you everyone for your suggestions. But I was wondering is there
> a way to code it up such that I don't need to do -summa- or -_pctile-
> and then look at the output to determine what the cutoff values will
> be for the top/bottom X% before I do the next step?

That is what the returned results are for, see:

*-------------- begin example --------------
sysuse nlsw88, clear

// get the 90th percentile, i.e. top 10%
_pctile wage, p(90)

// see what is left behind by -_pctile-
return list

// so the centile is stored in r(r1)
// to see why I used -float(r(r1))- see:
// http://blog.stata.com/2012/04/02/the-penultimate-guide-to-precision/#section6

// create a variable touse, which is 1
// when wage is in top 10% and 0 otherwise
gen byte touse = wage >= float(r(r1))

// use that variable to restric the sample
reg grade i.race if touse == 1

// store results
savedresults save mustbetrue e()

// a shorter (but not necessarily better or
// clearer) way of writing the same thing
reg grade i.race if touse

// check if current results are the same as
// stored results
savedresults compare mustbetrue e(), ///
    exclude(macros: cmdline)

// you can ofcourse still change the data
keep if touse
reg grade i.race

// check if current results are the same as
// stored results
savedresults compare mustbetrue e(), ///
    exclude(macros: cmdline)
*--------------- end example ---------------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )

Hope this helps,
Maarten

---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany

http://www.maartenbuis.nl
---------------------------------
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index