Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • T-tests for a matrix

    Hi,

    This is a sample of my data:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(time change5 interest3 excess_ri_port)
    578 1 3  -.6925126
    579 1 3   3.500199
    580 1 3   2.992766
    581 1 3  -7.831552
    582 1 3  -5.636639
    583 1 3   1.427559
    584 1 3 -14.535248
    585 1 3  -26.12037
    586 1 3  -6.152879
    587 1 3   7.726166
    657 2 1  -.8846533
    658 2 1    3.60806
    660 2 1   1.938433
    661 2 1    6.38167
    662 2 1  -2.021422
    663 2 1   5.012726
    664 2 1   .4726349
    665 2 1  -1.480696
    666 2 1   3.192597
    667 2 1  -5.435805
    668 2 1 -2.5471926
    669 2 1   7.368956
    670 2 1   .8326083
    671 2 1 -1.6570904
    672 2 1  -5.966536
    673 2 1   .4660656
    674 2 1   8.600153
    675 2 1  1.5384797
    676 2 1   .4725932
    677 2 1  -6.599574
    678 2 1   6.505339
    679 2 1   .5697324
    680 2 1  2.1315773
    681 2 1  -4.011961
    682 2 1  -1.068154
    683 2 1   4.434777
    684 2 1  4.2806845
    685 2 1  2.0386615
    686 2 1  4.1449623
    687 2 1   6.499111
    688 2 1   5.262307
    689 2 1 -1.0671136
    690 2 1   4.645394
    691 2 1  1.3541282
    692 2 1  4.2406955
    693 2 1  1.0949044
    694 2 1  .43575725
    695 2 1  1.9311043
    696 2 1   7.963739
    697 2 1  -4.701449
    698 2 1 -1.0655196
    end
    format %tm time
    My data is divided into 5 portfolios depending on the leverage change (change5) and into terciles depending on the interest rate (interest3). I have computed the average excess return for each change5 for each interest3 as following:
    Code:
    bysort change5 interest3 (time): tabstat excess_ri_port, stats(count mean p50 sd min max)
    What I want is to perform a t-test between the lowest and highest group. Because I get a matrix, there are 8 t-tests (see picture). For example, for interest3 == 1, calculate the t-test between change5 == 1 and change5 == 5. Or for change5 == 1, calculate the t-test between interest3 == 1 and interest3 == 3.

    Here is the matrix to make it a little bit more clear:

    Click image for larger version

Name:	Knipsel.JPG
Views:	1
Size:	34.4 KB
ID:	1671241


    Thanks

  • #2
    Juan, you may generate all group means and conduct all t tests from a single regression.

    Code:
    regress excess_ri_post bn.change5#bn.interest3, noc
    
    * Ttest 1
    lincom 1.change5#1.interest3 - 5.change5#1.interest3
    
    * Ttest 2
    lincom 1.change5#2.interest3 - 5.change5#2.interest3
    
    * Ttest 3
    lincom 1.change5#3.interest3 - 5.change5#3.interest3
    
    * Ttest 4
    lincom 1.change5#1.interest3 - 1.change5#3.interest3
    
    * Ttest 5
    lincom 2.change5#1.interest3 - 2.change5#3.interest3
    
    * Ttest 6
    lincom 3.change5#1.interest3 - 3.change5#3.interest3
    
    * Ttest 7
    lincom 4.change5#1.interest3 - 4.change5#3.interest3
    
    * Ttest 8
    lincom 5.change5#1.interest3 - 5.change5#3.interest3

    Comment


    • #3
      Thank you very much!

      Comment


      • #4
        Juan:
        as an aside to Fei's helpful code, as you seemingly have multiple comparisons, you may want to consider something like Bonferroni's correction (which is not directly available from -lincom-, but can be easily calculated by hand; see -contrast- entry, Stata .pdf manual).
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment

        Working...
        X