Announcement

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

  • #16
    The % of the entire population

    The % of the entire male population

    are different things. Here's some technique. percent is percent of everyone. percent(sex) would give conditional distributions on sex.

    Note the xrescale suboption.

    Over to you, now, to fiddle further.


    Code:
    catplot sex school [fw=_freq], by(jobs, xrescale note("")) percent asyvars bar(1, bfcolor(blue*0.5))  bar(2, bfcolor(pink*0.5))
    Click image for larger version

Name:	jobs2.png
Views:	1
Size:	13.3 KB
ID:	1337788

    Comment


    • #17
      Oh yes! That's perfect!
      Thank you very very much, you have been so helpful!

      Comment


      • #18
        I see you solved this, but here's another solution. There was an error in #3. It should have been (mean) instead of (percent) in the graph command.

        Code:
        separate Sex, by(Sex)
        preserve
        collapse (percent) Sex0 Sex1, by(Jobs School)
        list
        graph hbar (mean) Sex0 Sex1  , over(School) by(Jobs, xrescale col(1)) legend(lab(1 "new label 1") lab(2 "new label 2")) ysize(10)
        restore
        Stata/MP 14.1 (64-bit x86-64)
        Revision 19 May 2016
        Win 8.1

        Comment


        • #19
          Thank you both! Carole's solution it's also good, there's only a remaining problem about the percentages (the bars are of the good length, but it looks like they are scaled differently - in fact, their "apparence" is as in Nick's graph, but the sum of all the bars, which should correspond to the entire population, is not 100). But I think this is a minor problem, I guess I can figure it out.

          Just a related question: I am looping on School since I have different sets of variables (9), so at every loop I am doing preserve/restore. Is that the efficient way? It looks like every time it restores it has to reload the entire dataset (which is actually quite huge and therefore time consuming)...

          Comment


          • #20
            preserve and restore are indeed brute force heaving around. I can't see your code to comment, but it's possible that what you want can be achived by a loop over variables and/or an if qualifier. If that doesn't answer your question, post some code to get detailed advice.

            Comment

            Working...
            X