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

From |
Tirthankar Chakravarty <tirthankar.chakravarty@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: test difference in quintiles |

Date |
Wed, 10 Jun 2009 17:05:03 +0100 |

<> I will assume your conditioning variables Y & Z are binary. In the -auto- dataset, consider that you want to test the difference in the 5th percentile of the variable "mpg" if price is greater than $6000 (condition1, variable "pricedummy") or if the car is of foreign origin (condition 2, variable "foreign"). Then the code below should do what you want. Also, it might be a good idea to plot the kernel density estimates when considering tail-behaviour of distributions. Else if you only have one conditioning variable (case1, cond_var==1; case 2, cond_var==0), then Martin's code is probably more useful. /* More on bootstrapping percentiles */ sysuse auto, clear g pricedummy=(price>6000) tab pricedummy cap prog drop pctile_bs program define pctile_bs, rclass version 10 syntax varlist(max=3 min=3) [if] [in] marksample touse tokenize `varlist' local first `1' macro shift local second `1' macro shift local third `1' _pctile `first' if (`touse' & `second'==1), percentiles(5) scalar pc1 = r(r1) _pctile `first' if (`touse' & `third'==1), percentiles(5) scalar pc2 = r(r1) return scalar dpc = pc1-pc2 ereturn post, esample(`touse') end bootstrap Dpc = r(dpc), reps(2000) dots: pctile_bs mpg foreign pricedummy twoway (kdensity mpg if foreign==1) (kdensity mpg if pricedummy==1, legend(order(1 "foreign" 2 "pricedummy"))) /* end */ Simply substitute your variables in the line as follows: bootstrap Dpc = r(dpc), reps(2000) dots: pctile_bs X Y Z T --- References --- Statalist discussion: http://www.stata.com/statalist/archive/2004-02/msg00618.html On Wed, Jun 10, 2009 at 4:44 PM, Martin Weiss<martin.weiss1@gmx.de> wrote: > > <> > > Try: > > ************* > clear* > set obs 10000 > capt prog drop differ > > gen x= rnormal() > > /*no systematic difference btw > groups > THIS IS equivalent to your > Y and Z conditions*/ > gen condition=runiform()<0.5 > > pr differ, rclass > vers 10.1 > qui su x if /* > */ condition==0,/* > */ det > loc first=r(p5) > qui su x if /* > */ condition==1,/* > */ det > ret sca diff = r(p5)-`first' > end > > bs diff=r(diff), /* > */ reps(200): differ > > ************* > > > > HTH > Martin > > > -----Ursprüngliche Nachricht----- > Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Susanne Neckermann > Gesendet: Mittwoch, 10. Juni 2009 17:38 > An: statalist@hsphsun2.harvard.edu > Betreff: Re: st: test difference in quintiles > > Dear T > > thank you very much for the message!! > I am a real beginner with Stata and I have to admit that I do not > quite understand how to transfer the code to my case. > I have a variable X that I observe under two conditions Y and Z. I > want to see if the fifth percentile of variable X in condition Y is > different from the fifth percentile of X in condition Z. > > Thank you so much for your input!! > Best > Susanne > > On 10-Jun-09, at 5:26 PM, Tirthankar Chakravarty wrote: > >> <> >> >> This is a variation of previous advice: >> http://www.stata.com/statalist/archive/2009-05/msg00311.html >> >> I believe you want to test the significance of the difference of the >> 5th percentile for two variables using a bootstrap. If this is the >> case, then the code below applies: >> >> /* Bootstrap the difference of percentiles */ >> clear >> webuse nlswork, clear >> keep idcode year ttl_exp >> reshape wide ttl_exp, i(idcode) j(year) >> >> cap prog drop pctile_bs >> program define pctile_bs, rclass >> version 10 >> syntax varlist(max=2 min=2) [if] [in] >> marksample touse >> tokenize `varlist' >> local first `1' >> macro shift >> local second `*' >> _pctile `first' if `touse', percentiles(5) >> scalar pc1 = r(r1) >> _pctile `second' if `touse', percentiles(5) >> scalar pc2 = r(r1) >> return scalar dpc = pc1-pc2 >> ereturn post, esample(`touse') >> end >> bootstrap Dpc = r(dpc), reps(2000) dots: pctile_bs ttl_exp68 >> ttl_exp69 >> /* End */ >> >> Please also see the reference about pivotal statistics in a bootstrap >> from the previous message. >> >> T >> >> >> On Wed, Jun 10, 2009 at 3:57 PM, Susanne >> Neckermann<sneckermann@iew.uzh.ch> wrote: >>> Hi! >>> >>> I want to test whether the difference in the fifth percentile of two >>> distributions is significant. >>> In principle, this test should be similar to the "median" (thats >>> the name of >>> the command) test already implemented in Stata, but unfortunately I >>> cannot >>> program .ado files and I could not find a user-written procedure. >>> Any idea how to go about this? >>> P.S. the number of observations in the fifth percentile is pretty low >>> (around 6), so one might have to use something with bootstrap or >>> permutations. >>> >>> Thank you so much in advance >>> susanne >>> >>> >>> >>> * >>> * For searches and help try: >>> * http://www.stata.com/help.cgi?search >>> * http://www.stata.com/support/statalist/faq >>> * http://www.ats.ucla.edu/stat/stata/ >>> >> >> >> >> -- >> To every ω-consistent recursive class κ of formulae there correspond >> recursive class signs r, such that neither v Gen r nor Neg(v Gen r) >> belongs to Flg(κ) (where v is the free variable of r). >> >> * >> * For searches and help try: >> * http://www.stata.com/help.cgi?search >> * http://www.stata.com/support/statalist/faq >> * http://www.ats.ucla.edu/stat/stata/ > > > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/statalist/faq > * http://www.ats.ucla.edu/stat/stata/ > > > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/statalist/faq > * http://www.ats.ucla.edu/stat/stata/ > -- To every ω-consistent recursive class κ of formulae there correspond recursive class signs r, such that neither v Gen r nor Neg(v Gen r) belongs to Flg(κ) (where v is the free variable of r). * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**Re: st: Need to Title a Second Y-Axis...***From:*Maarten buis <maartenbuis@yahoo.co.uk>

**RE: st: Need to Title a Second Y-Axis...***From:*"Ploutz-Snyder, Robert (JSC-SK)[USRA]" <robert.ploutz-snyder-1@nasa.gov>

**st: test difference in quintiles***From:*Susanne Neckermann <sneckermann@iew.uzh.ch>

**Re: st: test difference in quintiles***From:*Tirthankar Chakravarty <tirthankar.chakravarty@gmail.com>

**Re: st: test difference in quintiles***From:*Susanne Neckermann <sneckermann@iew.uzh.ch>

- Prev by Date:
**AW: st: test difference in quintiles** - Next by Date:
**st: How to interpret a propensity matching result (log-transformation)?** - Previous by thread:
**AW: st: test difference in quintiles** - Next by thread:
**Re: st: test difference in quintiles** - Index(es):

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