Announcement

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

  • Categorical data - Graphical Representation

    Hello,

    I have three categorical variables and I wanted some sort of graphical representation for my thesis.
    My topic is association between asthma and anxiety over the time period of 2012-2014.
    My variables look like this.

    . tab ConDr

    Doctor diagnosed asthma | Freq. Percent Cum.
    ------------------------+-----------------------------------
    Yes | 1,199 19.90 19.90
    No | 4,825 80.10 100.00
    ------------------------+-----------------------------------
    Total | 6,024 100.00

    . tab GHQg2

    (D) GHQ Score - grouped |
    (0,1-3,4+) | Freq. Percent Cum.
    ------------------------+-----------------------------------
    Score 0 | 3,229 58.29 58.29
    Score 1-3 | 1,431 25.83 84.12
    Score 4+ | 880 15.88 100.00
    ------------------------+-----------------------------------
    Total | 5,540 100.00

    . tab SYear

    Survey year | Freq. Percent Cum.
    ------------+-----------------------------------
    2012 | 1,964 32.58 32.58
    2013 | 2,143 35.54 68.12
    2014 | 1,922 31.88 100.00
    ------------+-----------------------------------
    Total | 6,029 100.00

    I wonder if someone could help me out with the appropriate stata command.
    I tried this command gr bar GHQg2, by(ConDr SYear).
    Click image for larger version

Name:	Graph.PNG
Views:	1
Size:	14.4 KB
ID:	1349883

    However I'd like the three categories of GHQg2 also taken into account. Not Its mean value.

    Thank you.




  • #2
    Help us by showing the results of the 3 x 3 x 2 breakdown. Showing the results of this would suffice:

    Code:
    ssc inst groups
    groups ConDr GHQg2 SYear

    Comment


    • #3
      Hello,

      I tried your command
      Got the following response.

      . ssc inst groups
      connection timed out -- see help r(2) for troubleshooting
      http://fmwww.bc.edu/repec/bocode/g/ either
      1) is not a valid URL, or
      2) could not be contacted, or
      3) is not a Stata download site (has no stata.toc file).


      ​I'm using STATA 12.
      Can you guide some other way.

      Thank you.

      Comment


      • #4
        groups is there on SSC and accessible. I just checked. So, the problem looks like your internet connection. See also help netio

        Alternatively, show us the results of


        Code:
        contract ConDr GHQg2 SYear
        list

        Comment


        • #5
          Click image for larger version

Name:	qq.PNG
Views:	1
Size:	16.5 KB
ID:	1349980


          Thank you.

          Comment


          • #6
            Sorry, but that's an image and I can't copy and paste usefully.

            http://www.statalist.org/forums/help#stata explains,

            Use dataex (SSC) or -- if you can't download that -- copy and paste the list output to between CODE delimiters.

            Comment


            • #7
              . contract ConDr GHQg2 SYear

              . list

              +----------------------------------+
              | SYear ConDr GHQg2 _freq |
              |----------------------------------|
              1. | 2012 Yes Score 0 195 |
              2. | 2013 Yes Score 0 239 |
              3. | 2014 Yes Score 0 184 |
              4. | 2012 Yes Score 1- 84 |
              5. | 2013 Yes Score 1- 111 |
              |----------------------------------|
              6. | 2014 Yes Score 1- 97 |
              7. | 2012 Yes Score 4+ 72 |
              8. | 2013 Yes Score 4+ 74 |
              9. | 2014 Yes Score 4+ 70 |
              10. | 2012 Yes . 22 |
              |----------------------------------|
              11. | 2013 Yes . 26 |
              12. | 2014 Yes . 25 |
              13. | 2012 No Score 0 872 |
              14. | 2013 No Score 0 906 |
              15. | 2014 No Score 0 830 |
              |----------------------------------|
              16. | 2012 No Score 1- 341 |
              17. | 2013 No Score 1- 421 |
              18. | 2014 No Score 1- 377 |
              19. | 2012 No Score 4+ 221 |
              20. | 2013 No Score 4+ 229 |
              |----------------------------------|
              21. | 2014 No Score 4+ 214 |
              22. | 2012 No . 155 |
              23. | 2013 No . 136 |
              24. | 2014 No . 123 |
              25. | 2012 . Score 0 2 |
              |----------------------------------|
              26. | 2014 . Score 0 1 |
              27. | 2013 . . 1 |
              28. | 2014 . . 1 |
              +----------------------------------+

              .
              end of do-file

              Comment


              • #8
                I can use that, thanks, but CODE delimiters are not difficult! Please do see the link given.

                I'm assuming that diagnosis is the response. With tabplot installed, I engineer your listing and get this:

                Code:
                clear
                set scheme s1color
                input SYear str3 ConDr str2 GHQg2 _freq
                2012 Yes 0 195
                2013 Yes 0 239
                2014 Yes 0 184
                2012 Yes 1- 84
                2013 Yes 1- 111
                2014 Yes 1- 97
                2012 Yes 4+ 72
                2013 Yes 4+ 74
                2014 Yes 4+ 70
                2012 Yes . 22
                2013 Yes . 26
                2014 Yes . 25
                2012 No 0 872
                2013 No 0 906
                2014 No 0 830
                2012 No 1- 341
                2013 No 1- 421
                2014 No 1- 377
                2012 No 4+ 221
                2013 No 4+ 229
                2014 No 4+ 214
                2012 No . 155
                2013 No . 136
                2014 No . 123
                2012 . 0 2
                2014 . 0 1
                2013 . . 1
                2014 . . 1
                end
                
                replace ConDr = "" if ConDr == "."
                replace GHQg2 = "" if GHQg2 == "."
                
                tabplot ConDr SYear [fw=_freq], by(GHQg2, row(1) compact) percent(SYear GHQg2) showval
                See http://www.statalist.org/forums/foru...updated-on-ssc
                for more on tabplot.

                With your original data you should be able to do this directly with

                Code:
                set scheme s1color
                tabplot ConDr SYear, by(GHQg2, row(1) compact) percent(SYear GHQg2) showval
                Click image for larger version

Name:	asthma.png
Views:	1
Size:	40.7 KB
ID:	1349993






                On the other hand, something like

                Code:
                graph bar (mean) ConDr, over(SYear) by(GHQ, row(1))
                should show you fraction diagnosed in a direct way.
                Last edited by Nick Cox; 19 Jul 2016, 12:03.

                Comment


                • #9
                  Thank you for being patient with me but I couldn't still get results.

                  . replace ConDr = "" if ConDr == "."
                  type mismatch
                  . tabplot ConDr SYear [fw=_freq], by(GHQg2, row(1) compact) percent(SYear GHQg2) showval
                  unrecognized command: tabplot

                  .
                  . tabplot ConDr SYear, by(GHQg2, row(1) compact) percent(SYear GHQg2) showval
                  unrecognized command: tabplot


                  . graph bar (mean) ConDr, over(SYear) by(GHQ, row(1)
                  parentheses do not balance


                  Much Regards.



                  Comment


                  • #10
                    The graph bar works. Thank you very much.

                    Comment


                    • #11
                      But your graph is better but I can't reproduce it.

                      Comment


                      • #12
                        note that tabplot is a user-written command and must be downloaded and installed - use "search tabplot" to find and get instructions for a standard download

                        Comment


                        • #13
                          Working backwards:

                          Rich in #12: Thanks for underlining that tabplot is user-written.

                          Hajirah: The link in #9 does make that explicit. When we provide links, you are expected to read them!

                          Hajirah in #10 You left off a parenthesis. Look again at #9.

                          Code:
                          graph bar (mean) ConDr, over(SYear) by(GHQ, row(1))
                          Some of the code in my answer is just based on my engineering your results because you did not provide a data example in the requested form. Note again the important proviso "With your original data you should be able to do this directly with <code follows>".
                          But looking at ConDr results again, I sense a poor coding. With a diagnosis variable codes of 1 for Yes and 0 for No are most convenient. Then the mean over 0s and 1s is just the fraction diagnosed, which makes clinical and scientific and statistical sense, or so I suggest.

                          Comment


                          • #14
                            Thank you. I'll write my queries properly next time. Sorry for the inconvenience.
                            Much Regards.

                            Comment


                            • #15
                              Hello again.

                              I wanted to ask if other than the variables ConDr, SYear and GHQg2 variables defined above , I could make a graphical representation of my data including another categorical variable as well (T).


                              . tab T

                              T Freq. Percent Cum.
                              ------------------------+-----------------------------------
                              Yes | 959 53.10 53.10
                              No | 847 46.90 100.00
                              ------------------------+-----------------------------------
                              Total | 1,806 100.00


                              Thank you.

                              Comment

                              Working...
                              X