Announcement

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

  • T Tests and Wilcoxon Tests

    Hello Members

    I had been working on EViews for some time, I shifted to Stata now, since I am new, I have been trying to calculate T and Wilcoxon Tests of Difference (of two variables).
    I have about 24 different variables. VarA VarB VarC VarD and Var1 to Var20.

    I need to calculate T and Wilcoxon tests in this way:

    VarA = Var1
    VarB = Var2
    VarC= Var3
    VarD = Var4

    VarA = Var5
    VarB = Var6
    VarC = Var7
    VarD = Var8

    and so on to

    VarA = Var17
    VarB = Var18
    VarC = Var19
    VarD = Var20

    I need to do it for both tests and it will take a lot of time to do for both tests. And I also need to export these results to Excel or Word. The important results I need from these tests is the T and Z values, means and its differences and P value.

    I am simply using command for T-Test:
    ttest VarA=Var1 if sample_common==1 // for common sample
    and for Wilcoxon:
    signrank VarA=Var1 if sample_common==1

    I did it in EViews and it took days. Can anyone please help me in this matter for Stata. Any help will be highly appreciated.

    PS: I have other names for these variables on my Stata files. but if I needed to apply loop and if I had to change the names, I would.

    Many thanks in advance
    Qureshi Qazi
    Last edited by Qazi Qureshi; 31 Oct 2019, 10:56.

  • #2
    You may try something like:

    Code:
    set obs 20
    gen VarA = rnormal(18,2)
    gen VarB = rnormal(20,1)
    gen Var1 = rnormal(25,4)
    gen Var2 = rnormal(30, 3)
    foreach var1 of varlist VarA VarB {
    foreach var2 of varlist Var1 Var2 {
    ttest `var2' = `var1'
    signrank `var2' = `var1'
    }
    }
    Hopefully that helps.
    Best regards,

    Marcos

    Comment


    • #3
      Originally posted by Marcos Almeida View Post
      You may try something like:

      Code:
      set obs 20
      gen VarA = rnormal(18,2)
      gen VarB = rnormal(20,1)
      gen Var1 = rnormal(25,4)
      gen Var2 = rnormal(30, 3)
      foreach var1 of varlist VarA VarB {
      foreach var2 of varlist Var1 Var2 {
      ttest `var2' = `var1'
      signrank `var2' = `var1'
      }
      }
      Hopefully that helps.
      Thank you so much for you reply.
      But I honestly don't understand the code and also didn't get the desired results.
      The first error I had is the number of observations.
      I have total observations of 19393 out of which I have 3483 of common sample.
      I can't set observations to 20.
      Second, I have to make the tests between:

      VarA = Var1
      VarB = Var2

      VarA to VarD is different set of variables and Var1 to Var20 is different.

      And plus, I need to export these results to Excel or Word also.

      I definitely appreciate your reply, but I'll be very grateful if you could be more precise to my query.

      Many thanks!
      Qureshi

      Comment


      • #4
        You didn’t share data, albeit the FAQ recommendation on this. Therefore, since I wished to help you, I decided to do the extra effort and create data.

        This is a code. It applies to the variables I created. You must start with your dataset by typing from ‘foreach’.

        You’re also supposed to edit the name of the variables. For example, if you also have VarC , you add it in the code.


        Hopefully it is clear now.
        Best regards,

        Marcos

        Comment


        • #5
          To export the results to Excel, you may start by typing- help putexcel - for that matter.
          Best regards,

          Marcos

          Comment


          • #6
            Last but not least, shall you fail to understand the code, particularly the first lines, I fear you should start from the beginning and have an introductory grasp of Stata’s fundamental commands, then read about loops before delving with programming multiple comparisons. There is no point in bypassing these crucial steps. Learning the basics is utterly rewarding for everyone.
            Best regards,

            Marcos

            Comment


            • #7
              Originally posted by Marcos Almeida View Post
              You didn’t share data, albeit the FAQ recommendation on this. Therefore, since I wished to help you, I decided to do the extra effort and create data.

              This is a code. It applies to the variables I created. You must start with your dataset by typing from ‘foreach’.

              You’re also supposed to edit the name of the variables. For example, if you also have VarC , you add it in the code.


              Hopefully it is clear now.
              I am sorry but I tried to be clearer with my first post. And I highly appreciate your efforts and thank you for you help.

              Yes I understand, I am attaching the dataset:
              Name Data_Year VarA VarB VarC VarD Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9 Var10 Var11 Var12 Var13 Var14 Var15 Var16 Var17 Var18 Var19 Var20
              3Com Corp 2006 0.0637458 0.0896972 0.069065 0.0902528 0.236254 0.2103027 0.2309349 0.2097471 0.2827731 0.2568218 0.277454 0.2562662 0.033385 0.0074336 0.0280658 0.006878 0.2001381 0.2260894 0.2054572 0.226645 0.1597777 0.1857291 0.1650969 0.1862847
              3Com Corp 2007 0.1697762 0.1937015 0.1685596 0.1953236 0.2145254 0.2384507 0.2133089 0.2400729 0.1668212 0.1907465 0.1656047 0.1923687 0.0417864 0.0657117 0.0405699 0.0673339 0.2927838 0.3167091 0.2915672 0.3183312 0.2021317 0.226057 0.2009151 0.2276791
              3Com Corp 2008 0.017677 0.0154646 0.0193363 0.034823 0.0302582 0.0280458 0.0319175 0.0474042 0.0334074 0.0311951 0.0350667 0.0505535 0.0474686 0.0452562 0.0491279 0.0646146 0.0000398 0.0022522 0.0016195 0.0171062 0.0807175 0.0785051 0.0823768 0.0978635
              3Com Corp 2009 0.146232 0 0.1535088 0 0.146232 0 0.1535088 0 0.146232 0 0.1535088 0 0.146232 0 0.1535088 0 0.146232 0 0.1535088 0 0.146232 0 0.1535088 0
              3D Systems Corporation 2006 0.039646 0.0002017 0.0490905 0.0002017 0.0376315 0.0018129 0.047076 0.0018129 0.0235296 0.0159147 0.0329742 0.0159147 0.0043535 0.0437978 0.005091 0.0437978 0.0879061 0.0484617 0.0973506 0.0484617 0.0714036 0.0319593 0.0808481 0.0319593
              3D Systems Corporation 2007 0.0022994 0.0048056 0.0022994 0.0048056 0.0096738 0.0071676 0.0096738 0.0071676 0.0152432 0.012737 0.0152432 0.012737 0.0244391 0.0219328 0.0244391 0.0219328 0.0278582 0.025352 0.0278582 0.025352 0.0385958 0.0411021 0.0385958 0.0411021
              3D Systems Corporation 2008 0.0067805 0.001923 0.0067805 0.001923 0.0064265 0.001569 0.0064265 0.001569 0.0054388 0.0005812 0.0054388 0.0005812 0.0339265 0.029069 0.0339265 0.029069 0.0109098 0.0060523 0.0109098 0.0060523 0.0026519 0.0075094 0.0026519 0.0075094
              3D Systems Corporation 2009 0.0130916 0.0003427 0.0135114 0.0003427 0.0478432 0.0344089 0.048263 0.0344089 0.0323219 0.0188876 0.0327417 0.0188876 0.0155388 0.0289731 0.015119 0.0289731 0.0650194 0.0515851 0.0654392 0.0515851 0.0553274 0.0418931 0.0557472 0.0418931
              3D Systems Corporation 2010 0.010409 0.0018122 0.010409 0.0015592 0.0828836 0.0742869 0.0828836 0.0740339 0.0704323 0.0618355 0.0704323 0.0615825 0.0550714 0.0636682 0.0550714 0.0639212 0.0486886 0.0400919 0.0486886 0.0398389 0.0050111 0.0035856 0.0050111 0.0038386
              3D Systems Corporation 2011 0.0021588 0.0008885 0.0001263 0.0007615 0.0038179 0.0025476 0.0017854 0.0024206 0.0023259 0.0035963 0.0043584 0.0037233 0.0009045 0.0021748 0.002937 0.0023018 0.0282751 0.0270048 0.0262426 0.0268778 0.0107271 0.0119974 0.0127596 0.0121244
              3D Systems Corporation 2012 0.0348778 0.0360737 0.0345306 0.0362667 0.0452219 0.0464179 0.0448748 0.0466108 0.0459809 0.0471769 0.0456337 0.0473698 0.0273963 0.0285923 0.0270491 0.0287852 0.0241105 0.0253064 0.0237633 0.0254993 0.0527293 0.0539253 0.0523821 0.0541182
              3D Systems Corporation 2013 0.0146457 0.0113136 0.0146691 0.0112951 0.021642 0.0183099 0.0216654 0.0182914 0.0213064 0.0179744 0.0213298 0.0179559 0.0020182 0.0053502 0.0019948 0.0053687 0.0114132 0.0080812 0.0114366 0.0080627 0.0257735 0.0224415 0.0257969 0.022423
              3D Systems Corporation 2014 0.0068145 0.0063499 0.0067499 0.0063733 0.0076736 0.007209 0.007609 0.0072324 0.0064856 0.0060211 0.0064211 0.0060445 0.0001081 0.0005727 0.0001726 0.0005493 0.0084079 0.0079433 0.0083433 0.0079667 0.013846 0.0133814 0.0137814 0.0134048
              3D Systems Corporation 2015 0.1813983 0.1863056 0.1819054 0.1863167 0.2062616 0.2111689 0.2067686 0.21118 0.1640407 0.1689479 0.1645477 0.168959 0.1426128 0.14752 0.1431198 0.1475311 0.2045289 0.2094362 0.205036 0.2094473 0.2101264 0.2150337 0.2106335 0.2150448
              3D Systems Corporation 2016 0.0915455 0.092522 0.0915455 0.0926962 0.0569675 0.057944 0.0569675 0.0581183 0.0423561 0.0433326 0.0423561 0.0435068 0.068536 0.0695125 0.068536 0.0696867 0.0179263 0.0189028 0.0179263 0.019077 0.2386377 0.2396142 0.2386377 0.2397884

              Now, with this dataset, I have 24 variables and many more observations. Upto 19393.
              I have to apply T Test and Wilcoxon.
              I'll try to edit your code for VarC and VarD

              Thank you so much
              Qureshi

              Comment


              • #8
                Originally posted by Marcos Almeida View Post
                Last but not least, shall you fail to understand the code, particularly the first lines, I fear you should start from the beginning and have an introductory grasp of Stata’s fundamental commands, then read about loops before delving with programming multiple comparisons. There is no point in bypassing these crucial steps. Learning the basics is utterly rewarding for everyone.
                Yes, I believe I haven't done basics of Stata, so maybe I should start working on the basics.

                Many thanks
                Qureshi

                Comment

                Working...
                X