Announcement

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

  • generate t-stat

    How can we modify this code to generate t-stat of the means instead of standard deviation (sd), and also for 4*4 sorts.

    Code:
    frame create means_and_sds int (idiovol_group mcap_group) ///
        float(mean_vw sd_vw mean_ew sd_ew)
    forvalues iv = 1/5 {
        forvalues mc = 1/5 {
            summ vw_mean_q`mc'_idiovol_q`iv'_rt
            local mean_vw = r(mean)
            local sd_vw = r(sd)
            summ ew_mean_q`mc'_idiovol_q`iv'_rt
            local mean_ew = r(mean)
            local sd_ew = r(sd)
            frame post means_and_sds (`iv') (`mc') (`mean_vw') (`sd_vw') ///
                (`mean_ew') (`sd_ew')
        }
    }
    frame change means_and_sds
    rename (mean* sd*) =_idiovol_
    reshape wide *_idiovol_, i(mcap_group) j(idiovol_group)

  • #2
    To change this for 4*4 binning, just change 1/5 to 1/4 in both -forvalues- commands. Nothing more is needed for that.

    As for the t-statistics, do you want 2 separate t-statistics, one comparing mean_vw to 0 and the other comparing mean_ew to 0? Or do you want a single t-statistic comparing mean_ew to mean_vw?

    Comment


    • #3
      I need this one:
      I want 2 separate t-statistics, one comparing mean_vw to 0 and the other comparing mean_ew to 0.

      Comment


      • #4
        Code:
        frame create means_and_sds int (idiovol_group mcap_group) ///
            float(mean_vw sd_vw t_vw mean_ew sd_ew t_ew)
        forvalues iv = 1/4  {
            forvalues mc = 1/4 {
                summ vw_mean_q`mc'_idiovol_q`iv'_rt
                local mean_vw = r(mean)
                local sd_vw = r(sd)
                ttest vw_mean_q`mc'_idiovol_q`iv'_rt = 0
                local t_vw = r(t)
                summ ew_mean_q`mc'_idiovol_q`iv'_rt
                local mean_ew = r(mean)
                local sd_ew = r(sd)
                ttest ew_mean_q`mc'_idiovol_q`iv'_rt = 0
                local t_ew = r(t)
                frame post means_and_sds (`iv') (`mc') (`mean_vw') (`sd_vw') (`t_vw') ///
                    (`mean_ew') (`sd_ew') (`t_ew')
            }
        }
        frame change means_and_sds
        rename (mean* sd* t* ) =_idiovol_
        reshape wide *_idiovol_, i(mcap_group) j(idiovol_group)
        Changes in bold face.

        I did not remove the standard deviations. If you really don't want them, you can always drop them at the end.

        Comment


        • #5
          I tried the code #4 but there is some error that needs to be resolved. I append data example with a few variables and snapshot of error herewith.

          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input float(mdate vw_mean_mcap_q1_idiovol_q1_rt ew_mean_mcap_q1_idiovol_q1_rt vw_mean_mcap_q1_idiovol_q2_rt ew_mean_mcap_q1_idiovol_q2_rt)
          558  .009547775   .02479577   .02437658   .03475084
          559   .10438219   .11858144   .08377855   .08805264
          560   .08116962    .0792958   .07097481  .032742538
          561   .04498115   .04408213   .04740855  .024079055
          562 -.022288915  -.00587333   .03342637  .010281968
          563  .019821817  .016998773  .011102415  .007421346
          564  .067377895   .06323038  .016407823   .07976601
          565   -.1059341   -.0785012    -.150866  -.13820857
          566  -.07210954  -.05660603  -.06896405 -.067165166
          567   .08386143   .08955546   .10053737   .10737565
          568   .04357367   .05943481   .06094366    .0867588
          569  .024111053   .02701717    .0080635   .05110602
          570   .06358095    .0607609 -.031920392 -.016395649
          571   -.0270472  -.02999136  -.03761415 -.011755468
          572   .04246868   .04316803   .05046064   .06170107
          573  .007294329    .0467165   .02188667  .022017315
          574   .04165136   .04003866  .029694706   .04133752
          575   .22977667    .2277255    .2143408   .20428786
          576  -.22754773  -.22565822   -.2362953  -.27728713
          577   .00794934  .011074592 -.070291035  -.05864974
          578  -.15997925   -.1640525   -.1669928   -.1578676
          579   .10637853   .11093468   .09823243   .11571355
          580  -.02954163  -.03946456  -.05908868  -.06122958
          581  -.16585436   -.1590568   -.1615779  -.15867306
          582   .03693952   .04350401   .05151897   .05113066
          583  .012166202  .004758508  .036111612   .03958639
          584   -.1851966   -.1810432  -.21498574  -.20123994
          585   -.3348244   -.3217562   -.3549802   -.3421502
          586  -.10287447  -.08428375   -.1688749   -.1583635
          587   .09367303   .07917035   .09050088   .08274078
          588  -.06365843  -.06772166  -.07280084  -.05733358
          589  -.08381806  -.07905384   -.0422506   -.0204582
          590   .03771116   .03715475   .06624628   .04974006
          591   .19414186   .19908004   .27371666   .24236186
          592    .3274282    .3091991     .419429    .3985935
          593  .033857517  .008383145  .002679941  .022902023
          594   .11746235    .1435006   .10666234   .10002537
          595   .12716314    .1357516    .1760132    .1691689
          596    .1425892    .1412383   .07238307   .07065684
          597  -.03785864   -.0527435  -.05946851  -.03268821
          598    .0819361   .06925205   .10378387   .09575696
          599   .15803707    .1544773   .09632215    .1232953
          600 -.010999424 -.003957911 -.002746893   .02924245
          601  .000514733 -.001124334 -.003368403  .003616981
          602   .02170511  .030316364   .10812513   .11198892
          603    .0783469   .08806104   .10514018   .12258244
          604  -.07671385  -.07721204  -.06355686  -.06517138
          605   .05854668   .06292336    .1078936   .11029316
          606  .010707898  .032265536   .03949427   .04722167
          607  .032694664  .018592536 -.009044237   .00068132
          608   .04763261   .04564847   .11241443     .101737
          609   .03009066   .02293751    .0008051  .008618193
          610 -.030519104  -.04080753   -.1104302  -.11623478
          611  .007439347  .007219307   .03413117  .026593776
          612  -.13044187  -.12824793  -.09124906   -.0957571
          613  -.05239417  -.05904739   -.0648646  -.07034237
          614   .05894769    .0571517   .06899232   .07076477
          615   .08696517   .09987694   .06393108    .0686882
          616    -.040951  -.02531785  -.06234858  -.04622807
          617 -.027015405  -.02894352 -.014230093  -.02519445
          618   .02818784   .02450861   .07290703   .06457929
          619  -.08527008  -.10849579  -.16345036   -.1631169
          620 -.013742953 -.020762913  -.03907686 -.026884234
          621  -.01020511 -.011751142   .02321391  .034331482
          622  -.14280148  -.15280125  -.12470736  -.10832244
          623  -.10006838   -.0965528  -.08936226  -.08807243
          624   .14610061    .1563075   .17279357   .16941033
          625   .08852811   .07399375   .05945755    .0521311
          626  -.02549717 -.032774474  .001330905 -.003583591
          627    .0459909   .06156145   .06713442   .04878448
          628  -.04448419   -.0411814  -.07128345  -.05296824
          629  .036024313   .03982674   .08572852   .06328414
          630   .02592565   .03482852 -.002638496  -.02003376
          631  .016543996  .016940258  .007570951   .04160224
          632  .035490435   .05228644   .10778483   .08864895
          633  .011696635  .030955903   .02460151   .03971419
          634  .036192592   .04184807   .04925531   .06511546
          635  .018727016  .017574824  .022316355  .030821254
          636 -.063359216 -.068041295  .024449097  .010795265
          637  -.09276952   -.1063733   -.0967764   -.0975683
          638 -.016505292  -.04158242    -.120223  -.13017873
          639  .016715733  .016578164   .08983716   .08676432
          640  .018064087   .00524892 -.027863465 -.027553303
          641  -.04754739  -.05412241  -.05063578  -.06187253
          642  -.04007133  -.04559651 -.034037724 -.021941947
          643 -.012221493 -.004349294  -.06043958  -.05565551
          644   .05380223   .04430003   .05750297   .05579302
          645    .0800121   .08847322   .10312444   .12573172
          646   .07392643   .06666263    .0871317   .08839425
          647   .08568712   .08508613   .04637758   .05119117
          648 -.032748193 -.035004146  -.05185303  -.04392271
          649  .008319468  .017399747   .02489616   .01859344
          650    .1350643   .11971303   .12478655    .1241536
          651   .10595305   .11478766   .09209468   .12088978
          652   .13920607    .1494198   .20063406    .1954328
          653    .1514034   .15727663    .1581262    .1759043
          654   .02873998    .0507537 -.000114384   .01046246
          655  .028436223  .028203806   .08201407   .08138157
          656   .06895868   .07335494   .09946185   .11574554
          657  .008545064  .007172796   .02306144   .01921513
          end
          format %tm mdate
          Attached Files

          Comment


          • #6
            I should have asked for example data before writing the code in #4. I dug some up from one of our earlier threads, but it turns out that the variable names were different from what you show here. The following fixes the problem:

            Code:
            frame create means_and_sds int (idiovol_group mcap_group) ///
                float(mean_vw sd_vw t_vw mean_ew sd_ew t_ew)
            forvalues iv = 1/4  {
                forvalues mc = 1/4 {
                    summ vw_mean_mcap_q`mc'_idiovol_q`iv'_rt
                    local mean_vw = r(mean)
                    local sd_vw = r(sd)
                    ttest vw_mean_mcap_q`mc'_idiovol_q`iv'_rt = 0
                    local t_vw = r(t)
                    summ ew_mean_mcap_q`mc'_idiovol_q`iv'_rt
                    local mean_ew = r(mean)
                    local sd_ew = r(sd)
                    ttest ew_mean_mcap_q`mc'_idiovol_q`iv'_rt = 0
                    local t_ew = r(t)
                    frame post means_and_sds (`iv') (`mc') (`mean_vw') (`sd_vw') (`t_vw') ///
                        (`mean_ew') (`sd_ew') (`t_ew')
                }
            }
            frame change means_and_sds
            rename (mean* sd* t* ) =_idiovol_
            reshape wide *_idiovol_, i(mcap_group) j(idiovol_group)

            Comment


            • #7
              #6 works very well. Thanks indeed!

              Comment

              Working...
              X