Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.

# Re: st: Problem with decile significance test

 From Xixi Lin To statalist@hsphsun2.harvard.edu Subject Re: st: Problem with decile significance test Date Mon, 11 Mar 2013 22:37:01 -0400

Hi Jeph,

Thanks for the code. You are right that I wanna test whether the
top10% of Return is larger than bottom 10% of Return, sorted by
independent variables.

About the code, I have a question, is that only for equal variance
samples? I tried your code for a test, and here is the result:

. ttest Return if inlist(d_MB,1,10) & Period==120, by(d_MB)

Two-sample t test with equal variances
------------------------------------------------------------------------------
Group |     Obs        Mean    Std. Err.   Std. Dev.   [95% Conf. Interval]
---------+--------------------------------------------------------------------
1 |     136   -2.969485    1.284269    14.97703   -5.509375   -.4295957
10 |     135   -.6448148    .8480893    9.853907   -2.322188    1.032558
---------+--------------------------------------------------------------------
combined |     271   -1.811439    .7724542     12.7162   -3.332238   -.2906398
---------+--------------------------------------------------------------------
diff |            -2.32467    1.541284               -5.359185    .7098441
------------------------------------------------------------------------------
diff = mean(1) - mean(10)                                     t =  -1.5083
Ho: diff = 0                                     degrees of freedom =      269

Ha: diff < 0                 Ha: diff != 0                 Ha: diff > 0
Pr(T < t) = 0.0663         Pr(|T| > |t|) = 0.1327          Pr(T > t) = 0.9337

I am not very familiar with it,but the variance of the two samples are
not the same while it says "Two-sample t test with equal variances".
Am I using the right code?

Best,
Xixi Lin
On Mon, Mar 11, 2013 at 10:12 PM, Jeph Herrin <stata@spandrel.net> wrote:
> I don't understand what the variable -decile- is, in the statement:
>
>
>  "Then, I want to test for each decile, whether decile=1 is larger than
> decile=10."
>
> but I suppose you want something like this:
>
> *********************************************
>  foreach X in x1 x2 x3 {
>     xtile d_`X'=`X', nq(10)
>     qui ttest Return if inlist(d_`X',1,10) , by(d_`X')
>     di "`X'" _col(20) `r(p_u)'         // note r(p_u) is the upper test
> P-value
>  }
> **********************************************
>
> hth,
> Jeph
>
>
>
>
> On 3/11/2013 4:05 PM, Nick Cox wrote:
>>
>> Thanks for the extra detail.
>>
>> Same comment: such observations are necessarily disjoint, so you can't
>> use -ttest varname1 = varname2-.
>>
>> You will have various possibilities, but only
>>
>> variable 1                     variable 2
>>
>> non-missing                missing
>> missing                       non-missing
>> missing                       missing
>>
>> so there is nothing for -ttest- to work on.
>>
>> You must arrange your code to use -ttest varname, by(groupvar)-.
>>
>> By the way,
>>
>> 1. 120 periods and 5 response variables: you will have to take account
>> of multiplicity _and_ dependence in time in thinking about the pattern
>> of 600 t-tests.
>>
>> 2.
>>
>> foreach x of numlist 2/120 {
>>           replace d_X1=ceil(_n*10/_N) if Period==`x'
>> }
>>
>> looks unlikely to be what you want. _n and _N are here calculated with
>> reference to the entire dataset.
>>
>>
>> Nick
>>
>> On Mon, Mar 11, 2013 at 7:53 PM, Xixi Lin <winnielxx@gmail.com> wrote:
>>>
>>> Hi Nick,
>>>
>>> What I am trying to do is to create deciles for dependent variable
>>> according to independent variables (or sorted by independent
>>> variables), that is how the d_`x' are created. For example, d_X1 is
>>> the decile for dependent variable( Return) sorted by X1.
>>>
>>> Then, I want to test for each decile, whether decile=1 is larger than
>>> decile=10.
>>>
>>> Best,
>>> Xixi Lin
>>>
>>> On Mon, Mar 11, 2013 at 3:42 PM, Nick Cox <njcoxstata@gmail.com> wrote:
>>>>
>>>> I don't know exactly what you are trying to do here, but the nub of
>>>> the matter may be that
>>>>
>>>> observations for which -Return1- is calculated, namely
>>>>
>>>> if d_`x'==1 & Period==`z'
>>>>
>>>> and for which -Return2- is calculate, namely
>>>>
>>>> if d_`x'==10 & Period==`z'
>>>>
>>>> must be separate observations because it can't be true that something
>>>> is both 1 and 10.
>>>>
>>>> Hence, as you report,
>>>>
>>>>              ttest Return1=Return2 if Period==`z'
>>>>
>>>> finds no observations.
>>>>
>>>> Nick
>>>>
>>>> On Mon, Mar 11, 2013 at 7:33 PM, Xixi Lin <winnielxx@gmail.com> wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> I am trying to do decile significance test, however my codes does not
>>>>> work, can anyone help me to debug it?
>>>>>
>>>>> Here is my code:
>>>>> //create deciles according to independent variables
>>>>> sort X1
>>>>> by X1: gen d_X1=ceil(_n*10/_N)
>>>>>
>>>>> foreach x of numlist 2/120 {
>>>>>          replace d_X1=ceil(_n*10/_N) if Period==`x'
>>>>> }
>>>>> *****repeat the above code for each  independent variable
>>>>>
>>>>> //t statistics
>>>>> foreach x in X1 X2 X3 X4 X5 {
>>>>>         gen Return1_`x'=.
>>>>>             gen Return2_`x'=.
>>>>> foreach z of numlist 2/120 {
>>>>>         replace Return1_`x'=Return if d_`x'==1 & Period==`z'
>>>>>             replace Return2_`x'=Return if d_`x'==10 & Period==`z'
>>>>>             ttest Return1=Return2 if Period==`z'
>>>>>             display "`x'" "Period " "`z'" `r(p)'
>>>>>        }
>>>>>     }
>>>>>   ****it would be better if I can display p value for T>t not
>>>>> |T|>|t|******Anyone knows how to display that?
>>>>>
>>>>> The stata shows that "no observations". Does anyone know what is wrong
>>>>> with my code?
>>
>> *
>> *   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/
>>
>>
> *
> *   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/
*
*   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/