Announcement

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

  • Bar graph with Multiple Variable

    Hi Everyone,

    I am stuck at a problem but could not figure how to solve it. Below is an example of my dataset. Each row represents an observation (patients). The patients in the dataset may or may not have all the symptoms. Each presenting symptom is coded as a separate variable: facial_pain, hyposmia, anosmia headache etc. (0- Absent 1- Present).

    I want to create a single bar graph with multiple bars wherein each bar represent one particular symptom and all these bars are displayed next to each other as multiple bars.

    Thank you very much.

    Regards
    Pavan


    * Example generated by -dataex-. To install: ssc install dataex
    clear

    input byte(face_pain hypos anosmia headache cough)

    1 0 0 0 0
    1 0 0 1 0
    1 0 0 1 0
    1 1 0 1 1
    0 0 0 0 0
    1 0 0 1 0
    0 0 0 0 0





  • #2
    Something like?

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(face_pain hypos anosmia headache cough)
    1 0 0 0 0
    1 0 0 1 0
    1 0 0 1 0
    1 1 0 1 1
    0 0 0 0 0
    1 0 0 1 0
    0 0 0 0 0
    end
    
    gr hbar (sum) face_pain - cough, ascat bar(1, color(black%50)) scheme(s1color)
    Use the -relabel- option to relabel the bars.

    Comment


    • #3
      Thanks, Andrew.

      Something like this. Just one problem, it shows the sum, however, I want to display the percentage.


      For example, if my dataset has 200 or more patients, the sum would seem misleading. Thus, I want to display the percentage instead of the sum. Is this possible?


      Once again thank you very much for such a prompt reply.

      Comment


      • #4
        The mean of a 0/1 variable represents the proportion of 1s, so the percentage is this value times 100. Just manipulate the axis labels.

        Code:
        gr hbar face_pain - cough, ascat bar(1, color(black%50)) scheme(s1color) ylab(0 "0" 0.25 "25" 0.5 "50" 0.75 "75") ytitle("Percent")

        Comment


        • #5
          Consider also

          Code:
          ssc install statplot 
          statplot face_pain-cough

          Comment


          • #6
            Originally posted by Nick Cox View Post
            Consider also

            Code:
            ssc install statplot
            statplot face_pain-cough

            Hi Dr Nick,

            How can I plot "percentage" instead of "mean" using statplot? Can you give an example command for my data?

            Comment


            • #7
              The mean of several binary variables is a proportion. You can see percents just by adjusting the axis labels, so at 0.5 you show the text "50".

              Comment


              • #8
                Thank you very much, Prof Nick Cox and Andrew. The command and the package worked.

                One of my was variable coded as 0, 1, 2, 3; therefore the mean of that particular variable was shown greater in the graph than the actual proportion.

                Once again Thank you very much. Both of you. I really appreciate the prompt reply.

                Comment


                • #9
                  Hi Everyone,


                  Below is an example of data from the survival analysis.

                  The total duration of follow up is 18 years+. However, I want to restrict my survival analysis to the first five years since diagnosis.

                  datediag dead dateexit id perdiag agegrp
                  4429 1 4706 1570110 0 5
                  4533 1 6754 1570111 0 5
                  4387 1 4650 1570112 1 5
                  4669 1 4856 1570113 0 4
                  4123 1 4236 1570114 0 3
                  4883 0 4896 1570115 0 2
                  4324 1 4432 1570116 0 5
                  4129 1 4231 1349552 0 5
                  4114 1 4155 1349553 0 5
                  4220 1 4343 1349554 1 5
                  4201 1 4220 1349555 0 5
                  5332 1 5449 1349556 0 5


                  Could anyone suggest me what is the best way to restrict my analysis to FIRST FIVE YEARS SINCE DIAGNOSIS.

                  I am confused between the two methods:

                  * Generating duration variable
                  gen duration = dateexit - datediag


                  * We only want first five years after diagnosis
                  drop if duration > 1825


                  or using the stsplit command and restricting the analysis to first five years

                  stsplit fiveyears, at (5)
                  and
                  restricting the analysis by "if fiveyears==0" (like streg xxx if fiveyears==0, distribution (e))


                  The Hazard Ratios using the two methods are quite different. I don't know which method is correct.
                  Last edited by pavan pandey; 17 Sep 2020, 11:06.

                  Comment


                  • #10
                    Please start a new thread with #9 as it bears no relation to the thread title.

                    Comment


                    • #11
                      Dear Dr Nick, I specifically want to ask this question to you, that's why I have posted it here. I do not know how to tag you or anyone else in my new post.

                      I have already posted it as a new thread but was not getting any responses. Please help me if you can.
                      Last edited by pavan pandey; 17 Sep 2020, 11:57.

                      Comment


                      • #12
                        Thanks for the implied compliment but I didn't get beyond the title of the post you are referring.

                        https://www.statalist.org/forums/for...ince-diagnosis

                        -- as I am not a medical statistician and do not use survival analysis.

                        You started that thread at 16;51 BST and then posted a duplicate here at 17:53 (62 minutes later) because you'd not yet got a reply. But a reply came in from Paul Dickman at 20:53. Paul knows immensely more than I do about your topic. That's how Statalist works best.

                        Please read the Statalist FAQ Advice for hints on good practice, specifically https://www.statalist.org/forums/help#topiclines and https://www.statalist.org/forums/help#adviceextras #1 on,bumping.


                        Comment


                        • #13
                          Thank you very much Dr Nick. I will take a look at the links provided by you before posting any new questions here. Once again, Thank you very much for everything.

                          Best Regards,
                          Pavan

                          Comment

                          Working...
                          X