Announcement

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

  • Table with the Percentage of correct Answers

    Hello everyone,

    I just started working with stata, so my knowledge is very basic.
    My dataset includes several questions that respondents could answer on a scale from 1 - 4. The intention of these questions was to test the knowledge of respondents, so there is one correct answer, two incorrect answers and a category for "do not know".

    I want to create a table that shows the percentage of correct, incorrect and do not know answers.

    I want it to look like this:
    Question1 Question2 Question3
    Correct 40% 50% 60%
    Incorrect 40% 30% 30%
    Do not know 20% 20% 10%

    How do I do this? I know that I have to generate new variables for Correct, Incorrect and Do not know. I already thought of categorical variables which I generated like this for the first question, assume that option 1 was the correct answer:

    gen Question1_1 = .
    replace Question1_1 = 1 if Question1==1
    replace Question1_1 = 2 if Question1 >1 & <4
    replace Question1_1 = 3 if Question1==4

    This more or less gives me what I want for one question, but I have no idea how I can get this for all of my questions to show up in one table.

    Maybe anyone can help me out.

    Thank you in advance,

    Phi Dil

  • #2
    Try this:

    Code:
    ssc install tab_chi // installs the tabm command if you don't have it
    tabm Question_1 Question_2 ... Question_N, row transpose

    Comment


    • #3
      Please read this FAQ, since it will probably be helpful to you.
      Best regards,

      Marcos

      Comment


      • #4
        Thanks for your responses. I will check if that works for me.

        Comment


        • #5
          So the FAQ was helpful if I only had two variables I needed to match. But my problem occurs since I want to have an variable as an identifier for correct answers to 9 questions. How do I do that? I keep confusing myself with this.

          Comment


          • #6
            Let's suppose that the codes for the correct answers are, in order from Question_1 to Question_9, "143112443". The variable with the correct answer is:
            Code:
            gen str9 answercodes = "143112443"
            If you wanted these answers as numeric, and in separate variables, just do
            Code:
            gen byte answer1 = 1
            gen byte answer2 = 3
            .... etc.
            A better solution to your situation would involved storing the correct answer codes in a local macro, rather than a variable, but that's not something that's likely to be useful to you unless you have some programming experience.
            Last edited by Mike Lacy; 21 Jun 2019, 16:12.

            Comment


            • #7
              Let me try to explain it differently: assume you have three products: Shoes, Shirts, Pants, each can be in one of the following colors: Red, Green, Blue

              How do I make a table that shows me how big the share of each color for each product is?
              Shoes Shirts Pants
              Red 60% 30% 20%
              Green 30% 50% 20%
              Blue 10% 20% 60%
              I hope that this better explains my problem.

              Again, thank you all in advance.

              Comment


              • #8
                unless I'm completely confused, the basis for what you want was given above in #2; first the data from #7 but using -dataex-:
                Code:
                * Example generated by -dataex-. To install: ssc install dataex
                clear
                input float(shoes shirts pants)
                1 1 1
                1 1 1
                1 1 2
                1 2 2
                1 2 3
                1 2 3
                2 2 3
                2 2 3
                2 3 3
                3 3 3
                end
                label values shoes color
                label values shirts color
                label values pants color
                label def color 1 "red", modify
                label def color 2 "green", modify
                label def color 3 "blue", modify
                now, after installing tabs as per #2 above, the result:
                Code:
                . tabm shoes shirts pants, col transpose nofreq nokey
                
                           |             variable
                    values |     shoes     shirts      pants |     Total
                -----------+---------------------------------+----------
                       red |     60.00      30.00      20.00 |     36.67 
                     green |     30.00      50.00      20.00 |     33.33 
                      blue |     10.00      20.00      60.00 |     30.00 
                -----------+---------------------------------+----------
                     Total |    100.00     100.00     100.00 |    100.00

                Comment


                • #9
                  Thank you Rich! That table looks exactly like I want it to look!

                  I assume there is no way around tabm? When I try to run

                  ssc install tab_chi

                  Stata tells me that the file next.trk already exists, but still I get the error that tabm is unrecognized.

                  Comment


                  • #10
                    Naturally there are alternatives to tabm, such as your writing equivalent code yourself.

                    The problem with next.trk can be worked around by direct installation. Run

                    Code:
                    adopath
                    and see what adopath calls PLUS. On my current machine it is

                    Code:
                    c:\ado\plus
                    while on your machine it may well be different. Go to that directory or folder with some variant on

                    Code:
                    cd "c:\ado\plus"  
                    and then go to the subdirectory where program files whose names begin with t will be installed.

                    Code:
                    cd t
                    If Stata complains that this is not possible, then

                    Code:
                    mkdir t
                    and try again. Now you can

                    Code:
                    ssc copy tabm.ado 
                    ssc copy tabm.sthlp
                    Now you can back to where you were and try tabm.

                    If the problem with next.trk persists, you may need to ask again for advice.

                    Comment

                    Working...
                    X