Announcement

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

  • Using catplot to graph

    Hello,
    I have three variables that I would like to graph. They are school attendance(hv121), access to electricity(hv206), gender(hv104).
    P/S - all the variables are dummy variables

    I used the following commands:
    Code:
    ssc inst catplot
    Code:
    catplot hv104, hv206, percent(hv121) asyvars
    This is my output:
    Code:

    Kindly, how do I label the y-axis to be no electricity instead of no and electricity instead of yes?



    P/S. I did most of the manipulations from the graph itself

  • #2
    The graph is in posting #4
    Last edited by Anne Wanyonyi; 04 Jul 2016, 12:23.

    Comment


    • #3
      The graph is (so far) unreadable. See http://www.statalist.org/forums/help#stata for how to post graphs (save them first as .png).

      The syntax is illegal (too many commas). Do check carefully what you post.

      Comment


      • #4
        Apologies. I have posted it again.
        Last edited by Anne Wanyonyi; 04 Jul 2016, 13:01.

        Comment


        • #5
          Just change the value labels, i.e whatever is giving you "yes" or "no".

          NB the vertical axis here is not to Stata the y axis. See the help for graph hbar for an explanation.

          Comment


          • #6
            Hello Nick,

            Here is a snapshot of the graph again (I tried to do some corrections and re-upload but it ended up getting lost from the post #4)

            Click image for larger version

Name:	catplot.png
Views:	1
Size:	27.1 KB
ID:	1348832

            I finally managed to change the value labels but I realized the plotted values do not correspond to the values that I should expect:

            Code:
            bysort hv206: tab hv104 hv121
            Code:
            -> hv206 = no
            
                       |    member attended
                sex of | school during current
             household |      school year
                member |        no  attended  |     Total
            -----------+----------------------+----------
                  male |       326      4,199 |     4,525 
                female |       298      4,083 |     4,381 
            -----------+----------------------+----------
                 Total |       624      8,282 |     8,906 
            
            
            ----------------------------------------------------------------------------------------------------------
            -> hv206 = yes
            
                       |    member attended
                sex of | school during current
             household |      school year
                member |        no  attended  |     Total
            -----------+----------------------+----------
                  male |        41        824 |       865 
                female |        46        846 |       892 
            -----------+----------------------+----------
                 Total |        87      1,670 |     1,757
            hv121 is school attendance
            hv206 is access to electricity
            hv104 is gender

            If I use the above results from tab command, the fractions should be:
            Electricity: school attendance of males should be 0.51
            school attendance of females should be 0.4

            No electricity: school attendance of males should be 0.49
            school attendance of females should be 0.51

            The corrected formula I used for the catplot is :
            Code:
            catplot hv104 hv206, fraction(hv121) asyvars
            What could be bringing about the incorrect values in the graph? and how can I go about addressing it?

            Thank you.


            Comment


            • #7
              This is hard to follow, for several reasons:

              1. Contrary to advice in #3 and in the Statalist FAQ Advice, you are not posting graphs as .png attachments. Images are more difficult to read without clicking on them separately, which slows down understanding.

              2. You don't post example data, contrary to the Statalist FAQ Advice. It's possible to reconstitute your data from your tables, however.

              3. You don't make clear (to me) precisely what you want to plot. Which variable is response? Which are explanatory? If it's attendance as response, then it's clear from your tables that most children attend, which is far from your results implying about half.

              4. You don't seem troubled by the fact that you have a 3 way table with 2 x 2 x 2 = 8 cross-combinations, but your graph shows only 4 bars,

              5. Dopey variable names such as hv121 hv206 hv104 are completely unmemorable, at least to readers here, as shown by the fact that you have to keep explaining them.

              Here is a stab at what you may want. Fond though I am of catplot, it seems much simpler here, just to plot the mean non-attendance percents. As attendance averages about 95%, it is a much better use of space to plot the complement.

              Code:
              clear
              
              input attendance electricity female freq 
              0 0 0   326 
              0 0 1   298 
              0 1 0    41 
              0 1 1    46 
              1 0 0  4199  
              1 0 1  4083  
              1 1 0   824  
              1 1 1   846 
              end 
              
              label def female 0 male 1 female 
              label val female female 
              label def attendance 0 no 1 attended 
              label val attendance attendance 
              label def electricity 0 no 1 yes 
              label val electricity electricity 
              
              tab female attendance if !electricity [fw=freq] 
              
              bysort electricity : tab female attendance [fw=freq] 
              
              gen nonattendance = 100 * (1 - attendance) 
              
              graph bar (mean) nonattendance [w=freq] , over(female) over(electricity) ///
              ytitle(did not attend (%))


              Click image for larger version

Name:	attendance.png
Views:	1
Size:	12.3 KB
ID:	1348852


              Comment


              • #8
                Can I use markers option with catplot?

                Comment


                • #9
                  #8 If you use recast(dot) then the bars become point symbols or markers and you can change them. I am not clear whether that is what you are asking.

                  Comment

                  Working...
                  X