Announcement

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

  • Please help cant work out how to t-test. Im new to stata

    Hi guys I'm struggling to compare 2 different regions with a t-test.

    As seen from the screenshots I have multiple regions and have generated new separate variables for those 2 regions I want to test.
    One of my dependent variables is "patience".

    However, when I run the ttest it compares the region I select in the GroupVariable name with all the other existing regions. I am only looking to test patience on those 2 specific regions.

    Can someone help me please I'm a beginner.
    Thanks

    Attached Files

  • #2
    I will guess that your variable who region is a categorical variable whose values correspond to the different regions. Perhaps who_region==1 is ARegion and who_region==2 is ERegion.

    Then to compare patience in ARegion to patience in ERegion you will need to use a command like
    Code:
    ttest patience if inlist(who_region,1,2), by(who_region)
    In the dialog box, in the Main tab you will change the Group variable name to who_region, and on the by/if/in tab you will specify inlist(who_region,1,2) as the expression for the if.

    Comment


    • #3
      Im really not sure what to do, I don't understand the errors yet or what stata is telling me lol
      Attached Files

      Comment


      • #4
        In order to get a helpful response, you need to show some example data. I described what I guessed your data was like, and you did not tell me what I had wrong, although I suspect my assumptions about who_region are incorrect.

        To show your data, be sure to use the dataex command to do this. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, dataex is already part of your official Stata installation. If not, run ssc install dataex to get it. Either way, run help dataex and read the simple instructions for using it. dataex will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

        When asking for help with code, always show example data. When showing example data, always use the dataex command.

        More generally, please take a few moments to review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question. It is particularly helpful to copy commands and output from your Stata Results window and paste them into your Statalist post using code delimiters [CODE] and [/CODE], and to use the dataex command to provide sample data, as described in section 12 of the FAQ.

        The more you help others understand your problem, the more likely others are to be able to help you solve your problem.

        Comment


        • #5
          Originally posted by Graham Elmhurst View Post
          I don't understand the errors yet or what stata is telling me lol
          As William mentions, Stata is telling you that your grouping variable is string.

          Try something like the following:
          Code:
          ttest patience if inlist(strlower(who_region), "afro", "euro"), by(who_region)

          Comment


          • #6
            Graham:
            as an aside to previous helpful comments (which, as precious by-product, underline once more that using Stata effectively implies a relevant initial effort to get yourself familiar with all Stata'a amazing stuff, as William Lisowski wisely reminds on this forum from time to time), it is more careful to add the -unequal variance- option to your -ttest- code.
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment


            • #7
              Thank you all for your help and sorry as i am new to this.
              Joseph Coveney your code worked. Legend
              Thanks

              Comment

              Working...
              X