Announcement

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

  • Stata Graph

    Dear all, I have the database as the image below, and I would like to create a percentage graph with the variables P04_1 to P04_12 in the same figure, what is the command?


  • #2
    I can't see the image, and we ask that you don't use them as much as possible, anyways. Please see the FAQ for more, sections 12 13 and 14 specifically http://www.statalist.org/forums/help


    ADDED: Welcome to Statalist.

    Comment


    • #3
      I can see the image, but I can't scrape sample data from a screenshot. Here is some technique on fake data. I used catplot from SSC and one interpretation of how percents are to be calculated.

      Code:
      clear
      set seed 2803 
      set obs 100 
      forval j = 1/5 { 
          gen P04_`j' = runiform() < `j'/7 
      }
      
      * you start here 
      
      tab1 P04_* 
      
      preserve 
      
      gen id = _n 
      reshape long P04_, i(id) j(which)
      
      set scheme s1color 
      
      * must install first using                       ssc install catplot
      
      catplot P04_ which,  asyvars percent(which) recast(bar) ///
      bar(1, lcolor(red) fcolor(red*0.5)) bar(2, lcolor(blue) fcolor(blue*0.5)) ///
      t1title(explain variables here)
      
      
      restore
      Click image for larger version

Name:	catplot2.png
Views:	1
Size:	20.5 KB
ID:	1679127

      Comment


      • #4
        I'm having trouble showing the picture as a png. I present in a summarized way in the table below, how my data is represented. The idea is to present a graph with the 13 variables in question.
        P0_1 P0_2 P0_3 ... P0_12 P0_13
        1 0 1 1 0 0 1
        2 0 1 0 1 0 1
        3 1 0 0 0 1 0
        4 0 0 1 0 1 0
        .
        .
        .
        1 0 0 0 0 1
        3871 0 0 1 1 1 1

        Comment


        • #5
          Doesn't #3 give you what you want, where your code becomes

          Code:
          reshape long P0_, i(id) j(which)
          set scheme s1color
          ssc install catplot, replace
          
          catplot P0_ which, asyvars percent(which) recast(bar) ///
          bar(1, lcolor(red) fcolor(red*0.5)) bar(2, lcolor(blue) fcolor(blue*0.5)) ///
          t1title(explain variables here)
          assuming the variable in the first column of your table is named "id"? If not, how is it different from what you want?

          Comment


          • #6
            Thank you very much Prof. Niki Cox and Andrew Musau for the help and the tip, it is from this command that I am able to resolve my uneasiness, however when I follow the tip, I face myself with the problem below:

            gen id=_n
            . reshape long P04_, i(id) j(which)
            variable which contains all missing values

            Comment


            • #7
              Thank you very much Prof. Niki Cox and Andrew Musau for the help and the tip, it is from this command that I am able to resolve my uneasiness, however when I follow the tip, I face myself with the problem below:

              gen id=_n
              . reshape long P04_, i(id) j(which)
              variable which contains all missing values

              Comment


              • #8
                Please show the results of

                Code:
                describe P04* 
                
                summarize P04*
                Detail: I post as Nick and answer also to Nicholas. Niki may be someone else you know, but it's not a form that makes sense to me.

                Comment


                • #9
                  Describe P04_*

                  Variable Storage Display Value
                  name type format label Variable label
                  --------------------------------------------------------------------------------------------------------------
                  P04__1 byte %8.2f labels10 P04. Nos últimos 12 meses, em que meses este AF teve problemas
                  de alimentação
                  P04__2 byte %8.2f labels11 P04. Nos últimos 12 meses, em que meses este AF teve problemas
                  de alimentação
                  P04__3 byte %8.2f labels12 P04. Nos últimos 12 meses, em que meses este AF teve problemas
                  de alimentação
                  P04__4 byte %8.2f labels13 P04. Nos últimos 12 meses, em que meses este AF teve problemas
                  de alimentação
                  P04__5 byte %8.2f labels14 P04. Nos últimos 12 meses, em que meses este AF teve problemas
                  de alimentação
                  P04__6 byte %8.2f labels15 P04. Nos últimos 12 meses, em que meses este AF teve problemas
                  de alimentação
                  P04__7 byte %8.2f labels16 P04. Nos últimos 12 meses, em que meses este AF teve problemas
                  de alimentação
                  P04__8 byte %8.2f labels17 P04. Nos últimos 12 meses, em que meses este AF teve problemas
                  de alimentação
                  P04__9 byte %8.2f labels18 P04. Nos últimos 12 meses, em que meses este AF teve problemas
                  de alimentação
                  P04__10 byte %8.2f labels19 P04. Nos últimos 12 meses, em que meses este AF teve problemas
                  de alimentação
                  P04__11 byte %8.2f labels20 P04. Nos últimos 12 meses, em que meses este AF teve problemas
                  de alimentação
                  P04__12 byte %8.2f labels21 P04. Nos últimos 12 meses, em que meses este AF teve problemas
                  de alimentação
                  P04__13 byte %8.2f labels22 P04. Nos últimos 12 meses, em que meses este AF teve problemas
                  de alimentação

                  Summarize P04_*

                  Variable Obs Mean Std. dev. Min Max

                  P04__1 7,699 .5004546 .5000323 0 1
                  P04__2 7,699 .4636966 .4987127 0 1
                  P04__3 7,699 .3221198 .4673189 0 1
                  P04__4 7,699 .1836602 .387232 0 1
                  P04__5 7,699 .128718 .3349093 0 1

                  P04__6 7,699 .1148201 .3188254 0 1
                  P04__7 7,699 .1063775 .3083401 0 1
                  P04__8 7,699 .1227432 .3281635 0 1
                  P04__9 7,699 .1491103 .3562203 0 1
                  P04__10 7,699 .1730095 .37828 0 1

                  P04__11 7,699 .2109365 .4079999 0 1
                  P04__12 7,699 .2293804 .4204617 0 1
                  P04__13 7,699 .1828809 .386594 0 1



                  Note: The database has many other variables, my interest is currently only on the variables P04_*.

                  Comment


                  • #10
                    It looks to me as if you have two underscores __ not one _ in each variable name. If so, then

                    Code:
                     
                     reshape long P04__, i(id) j(which)
                    should work better than
                    Code:
                       
                     reshape long P04_, i(id) j(which)



                    Comment


                    • #11
                      Professor Nicholas Cox, thank you very much. Mission accomplished. The observation you had, was the detail that was needed. Sorry for the wrong treatment I gave your name in the previous message.

                      Comment

                      Working...
                      X