Announcement

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

  • catplot by group

    Hi Stata users,
    I am using a Stata user written command
    Code:
    catplot
    in Stata 17 to generate plots for categorical variable. I would specifically want to compare weighed an unweighted results but would want them to be in the same chart (i.e bar labels of the same option be adjacent to one another and have a legend differentiating the two groups) instead of the chart being produced through the by option.

    Below is the code am trying to play with
    Code:
    sysuse auto, clear
    
    expand 2, gen(indicator)
    lab def indicator 0 "Unweighted" 1 "Weighted"
    lab val indicator indicator
    ta indicator
    
    drop weight
    gen weight = (1/runiform()) if indicator == 1
    
    gl barsettings1    "bar(1, fcolor(navy) fintensity(inten40) lcolor(navy) lwidth(medium))" 
    
    count if !mi(foreign)
    catplot foreign, by(indicator) blabel(bar, format(%3.0f)) l1title("") title("") ytitle("Percent") percent note("N = `:display %05.0fc `r(N)''") $barsettings1
    
    count if !mi(foreign)
    catplot foreign [aweight = weight], by(indicator) blabel(bar, format(%3.0f)) l1title("") title("") ytitle("Percent") percent note("N = `:display %05.0fc `r(N)''") $barsettings1
    Thanks in advance!

  • #2
    Thanks for the clear reproducible example.

    catplot (c'est à moi) is from SSC. (You're asked to indicate provenance, that is, where it comes from.)

    I'd approach this as follows.

    1. The sample size should surely be calculated before the expand. The point of the expand is just to allow two plots from the same original dataset.

    2. An unweighted solution is, with suitable care, equivalent here to one with equal weights, which might as well be 1.

    Anyone playing with this example will note that caprice can bite hard with those weights. Hence set seed,

    Code:
    sysuse auto, clear
    
    set seed 2803 
    
    count if !missing(foreign)
    local n = r(N)
    
    expand 2, gen(indicator)
    lab def indicator 0 "Unweighted" 1 "Weighted"
    lab val indicator indicator
    ta indicator
    
    gen wt = cond(indicator == 1, (1/runiform()), 1) 
    
    gl barsettings1    "bar(1, fcolor(navy) fintensity(inten40) lcolor(navy) lwidth(medium))" 
    
    catplot foreign [aw=wt], by(indicator, note("{it:n} = `n'", size(medium))) blabel(bar, format(%3.0f)) l1title("") title("") ytitle("Percent") percent(indicator)  $barsettings1

    Click image for larger version

Name:	weighted_catplot.png
Views:	1
Size:	33.1 KB
ID:	1738962

    Comment


    • #3
      Nick Cox Thanks so much for the great insights.

      I am wondering whether it is possible to have the comparison as shown in the image below based on catplot

      Click image for larger version

Name:	Untitled.png
Views:	1
Size:	41.0 KB
ID:	1738973


      Credit: Stata.com

      Comment


      • #4
        Some more technique. Previous graph G1; new graphs G2 and G3.

        Code:
        sysuse auto, clear
        
        set seed 2803 
        
        count if !missing(foreign)
        local n = r(N)
        
        expand 2, gen(indicator)
        lab def indicator 0 "Unweighted" 1 "Weighted"
        lab val indicator indicator
        ta indicator
        
        gen wt = cond(indicator == 1, (1/runiform()), 1) 
        
        gl barsettings1    "bar(1, fcolor(navy) fintensity(inten40) lcolor(navy) lwidth(medium))" 
        
        catplot foreign [aw=wt], by(indicator, note("{it:n} = `n'", size(medium))) blabel(bar, format(%3.0f)) l1title("") title("") ytitle("Percent") percent(indicator)  $barsettings1 name(G1, replace)
        
        catplot foreign indicator [aw=wt], note("{it:n} = `n'", size(medium)) blabel(bar, format(%3.0f)) l1title("") title("") ytitle("Percent") percent(indicator)  $barsettings1 recast(bar) name(G2, replace)
        
        collapse (sum) wt, by(foreign indicator)
        
        egen Percent  = pc(wt), by(indicator)
        
        graph bar (asis) Percent, over(indicator) over(foreign) note("{it:n} = `n'", size(medium)) blabel(bar, format(%3.0f))  $barsettings1 name(G3, replace) ytitle(Percent)

        Comment


        • #5
          Nick Cox This is really brilliant!!! Thanks a ton for coming to my rescue. I sincerely appreciate your help.

          Comment


          • #6
            Thanks. But G4 here is a much better way to get G3.

            Code:
            sysuse auto, clear
            
            set seed 2803 
            
            count if !missing(foreign)
            local n = r(N)
            
            expand 2, gen(indicator)
            lab def indicator 0 "Unweighted" 1 "Weighted"
            lab val indicator indicator
            ta indicator
            
            gen wt = cond(indicator == 1, (1/runiform()), 1) 
            
            gl barsettings1    "bar(1, fcolor(navy) fintensity(inten40) lcolor(navy) lwidth(medium))" 
            
            catplot foreign [aw=wt], by(indicator, note("{it:n} = `n'", size(medium))) blabel(bar, format(%3.0f)) l1title("") title("") ytitle("Percent") percent(indicator)  $barsettings1 name(G1, replace)
            
            catplot foreign indicator [aw=wt], note("{it:n} = `n'", size(medium)) blabel(bar, format(%3.0f)) l1title("") title("") ytitle("Percent") percent(indicator)  $barsettings1 recast(bar) name(G2, replace)
            
            catplot  indicator foreign [aw=wt], note("{it:n} = `n'", size(medium)) blabel(bar, format(%3.0f)) l1title("") title("") ytitle("Percent") percent(indicator)  $barsettings1 recast(bar) name(G4, replace)
            
            
            collapse (sum) wt, by(foreign indicator)
            
            egen Percent  = pc(wt), by(indicator)
            
            graph bar (asis) Percent, over(indicator) over(foreign) note("{it:n} = `n'", size(medium)) blabel(bar, format(%3.0f))  $barsettings1 name(G3, replace) ytitle(Percent)

            Comment


            • #7
              Thanks so much Nick Cox for the additional trick. I sincerely appreciate

              I realize the example I shared is not reflective of my context. Below is an sample of my dataset

              ----------------------- copy starting from the next line -----------------------
              Code:
              * Example generated by -dataex-. For more info, type help dataex
              clear
              input int dem2 float weight
                1 .0008149959
                2 .0008149959
                2    .0909091
                2 .0008149959
                2  .004694836
                2  .003521127
                1  .011494253
                2 .0008149959
                2 .0008149959
                1  .009259259
                2   .01754386
                1  .003521127
                2 .0008149959
                1  .003521127
                1 .0008149959
                2 .0008149959
                1   .06666667
                2  .071428575
                2 .0008149959
                2 .0008149959
                1 .0008149959
                2   .00862069
                2 .0008149959
                2 .0008149959
                1   .00862069
                1  .010416667
                1 .0008149959
                1   .04761905
                2  .003521127
                1 .0008149959
                1   .00862069
                2 .0008149959
                1 .0008149959
                2 .0008149959
                2    .0909091
                2  .003521127
                . .0008149959
                1  .010416667
                1 .0008149959
                1  .011494253
                1 .0008149959
                2  .004694836
                1          .1
                1  .004694836
                1  .003521127
                1  .004694836
                1   .03448276
                1 .0008149959
                1   .06666667
                1  .004694836
                2 .0008149959
                .  .033333335
                2  .009259259
                2  .009259259
                1   .00862069
                2 .0008149959
                1 .0008149959
                2 .0008149959
                2 .0008149959
                2 .0008149959
                1 .0008149959
                2 .0008149959
                2  .004694836
                2 .0008149959
                1  .003521127
                2 .0008149959
                1   .03448276
                1  .004694836
                2 .0008149959
                1 .0008149959
                2 .0008149959
                1 .0008149959
                2  .003521127
                2 .0008149959
                1   .00862069
                1 .0008149959
                2 .0008149959
                2  .009259259
                1  .010416667
                2 .0008149959
                2 .0008149959
                1  .010416667
                2 .0008149959
                1   .07692308
                2 .0008149959
                .  .033333335
                2 .0008149959
                2  .009259259
                2 .0008149959
                2 .0008149959
                1 .0008149959
                1   .00862069
                2 .0008149959
                2  .003521127
                1          .1
                1  .004694836
                1 .0008149959
                2 .0008149959
                1         .04
                1  .010416667
                1 .0008149959
                2 .0008149959
                1         .04
                2   .01754386
                1 .0008149959
                1 .0008149959
                2 .0008149959
                1  .010416667
                1   .05555556
                2 .0008149959
                1  .010416667
                2   .06666667
                2 .0008149959
                1 .0008149959
                2  .003521127
                1 .0008149959
                1    .0909091
                1 .0008149959
                2  .004694836
                1  .004694836
                1   .00862069
                2  .004694836
                2 .0008149959
                2  .004694836
                1  .009259259
                1  .071428575
                1  .033333335
                1 .0008149959
                2 .0008149959
                2 .0008149959
                1   .04761905
                2 .0008149959
                1   .01754386
                2  .003521127
                1 .0008149959
                2   .04166667
                2   .06666667
                1 .0008149959
                1 .0008149959
                2 .0008149959
                2 .0008149959
                1 .0008149959
                1  .071428575
                2 .0008149959
                1  .010416667
                2 .0008149959
                2 .0008149959
                1 .0008149959
                2 .0008149959
                1 .0008149959
                2  .003521127
                1 .0008149959
                1   .01754386
                1 .0008149959
                1   .04545455
                2 .0008149959
                1  .009259259
                .  .003521127
                2 .0008149959
                1   .00862069
                1   .00862069
                1  .003521127
                2 .0008149959
                2 .0008149959
                2 .0008149959
                1  .004694836
                1  .003521127
                1 .0008149959
                1  .010416667
              700  .003521127
                1   .01754386
                1 .0008149959
                2 .0008149959
                1  .004694836
                2 .0008149959
                1  .009259259
                1   .00862069
                .  .033333335
                2 .0008149959
                2 .0008149959
                2 .0008149959
                2 .0008149959
                2 .0008149959
                2  .003521127
                2 .0008149959
                2 .0008149959
                1 .0008149959
                1   .02857143
                2  .003521127
                2   .05555556
                2    .0909091
                2 .0008149959
                2 .0008149959
                1   .04166667
                1 .0008149959
                2 .0008149959
                1   .06666667
                2 .0008149959
                2 .0008149959
                2 .0008149959
                1    .0909091
                1 .0008149959
                2 .0008149959
                2   .00862069
                1 .0008149959
                1 .0008149959
                1  .004694836
                1 .0008149959
                2 .0008149959
                2 .0008149959
                2 .0008149959
                2   .04166667
                2 .0008149959
                1  .003521127
                1  .011494253
                1    .0909091
                2  .010416667
                1  .003521127
                1  .003521127
                2  .003521127
                1  .004694836
                2  .009259259
                2   .06666667
                2 .0008149959
                2  .003521127
                1  .011494253
                1 .0008149959
                1  .011494253
                1  .010416667
                1 .0008149959
                2 .0008149959
                .  .033333335
                2 .0008149959
                1    .0909091
                1 .0008149959
                2 .0008149959
                .  .033333335
                2   .01754386
                1  .004694836
                1   .02857143
                1   .00862069
                . .0008149959
                1  .011494253
                1  .010416667
                2  .009259259
                1  .003521127
                2 .0008149959
                2   .05555556
                1 .0008149959
                2   .04545455
                1   .00862069
                1   .03448276
                2 .0008149959
                1   .00862069
                2  .003521127
                2 .0008149959
                1  .003521127
                2 .0008149959
                2 .0008149959
                1  .011494253
                1 .0008149959
                1 .0008149959
                .  .033333335
                2  .004694836
                2 .0008149959
                2  .009259259
                1   .03448276
                1  .004694836
                2 .0008149959
                2  .071428575
                1 .0008149959
                1    .0909091
                2  .004694836
                .  .033333335
                1   .03448276
                1   .02857143
                1  .009259259
                . .0008149959
                1 .0008149959
                2 .0008149959
                1   .06666667
                1          .1
                2 .0008149959
                2 .0008149959
                1   .03448276
                2 .0008149959
                2 .0008149959
                2 .0008149959
                2 .0008149959
                1    .0909091
                2 .0008149959
                1  .071428575
                1 .0008149959
                1    .0909091
                1  .011494253
                2   .01754386
                1    .0909091
                1   .00862069
                1  .004694836
                1  .010416667
                2 .0008149959
                2 .0008149959
                1          .1
                1  .010416667
                2  .004694836
                1  .003521127
                1  .011494253
                1 .0008149959
                1  .003521127
                2 .0008149959
                2 .0008149959
                1  .010416667
                1 .0008149959
                1   .05555556
                1  .003521127
                1   .00862069
                1  .010416667
                1  .003521127
                1 .0008149959
                2    .0909091
                1 .0008149959
                1  .004694836
                1  .009259259
                2 .0008149959
                2 .0008149959
                1         .04
                2 .0008149959
                1    .0909091
                1   .00862069
                2  .003521127
                1 .0008149959
                2  .009259259
                2  .003521127
                1  .004694836
                1 .0008149959
                1 .0008149959
                2 .0008149959
                1  .003521127
                2 .0008149959
                2 .0008149959
                2 .0008149959
                2 .0008149959
                1 .0008149959
                1  .009259259
                2 .0008149959
                1   .00862069
                1 .0008149959
                2 .0008149959
                2 .0008149959
                1  .011494253
                1 .0008149959
                1   .01754386
                1 .0008149959
                2  .003521127
                2 .0008149959
                1  .010416667
                2  .004694836
                2  .003521127
                1  .004694836
                2  .003521127
                2 .0008149959
                1  .004694836
                2 .0008149959
                1  .004694836
                1  .010416667
                1 .0008149959
                . .0008149959
                1 .0008149959
                1   .01754386
                2 .0008149959
                2 .0008149959
                1    .0909091
                2 .0008149959
                1  .009259259
                1  .003521127
                1   .01754386
                2  .003521127
                2 .0008149959
                2 .0008149959
                2 .0008149959
                1 .0008149959
                2 .0008149959
                1 .0008149959
                1   .05555556
                1  .003521127
                1 .0008149959
                1 .0008149959
                1 .0008149959
                2 .0008149959
                2 .0008149959
                1 .0008149959
                1   .03448276
                1  .004694836
                2 .0008149959
                2  .003521127
                2  .004694836
                1 .0008149959
                2   .00862069
                1  .010416667
                1 .0008149959
                2  .003521127
                2  .009259259
                .  .033333335
                1 .0008149959
                2 .0008149959
                2 .0008149959
                2 .0008149959
                1 .0008149959
                2 .0008149959
                1  .003521127
                1   .00862069
                1  .011494253
                2  .003521127
                2  .009259259
                2  .004694836
                2  .004694836
                2  .003521127
                1    .0909091
                2  .003521127
                2 .0008149959
                2 .0008149959
                1 .0008149959
                2  .004694836
                1   .00862069
                2 .0008149959
                2  .003521127
                2 .0008149959
                2 .0008149959
                2  .003521127
                1  .010416667
                2   .01754386
                2 .0008149959
                1  .004694836
                1 .0008149959
                1          .1
                1          .1
                2 .0008149959
                2 .0008149959
                2 .0008149959
                2  .009259259
                1   .03448276
                1  .004694836
                1          .1
                1 .0008149959
                2 .0008149959
                2 .0008149959
                2 .0008149959
                2  .009259259
                1  .004694836
                1  .010416667
                .  .033333335
                1  .009259259
                2  .009259259
                1  .010416667
                2 .0008149959
                1  .010416667
                2   .00862069
                2         .04
                2         .04
                2 .0008149959
                .  .033333335
                1 .0008149959
                1  .071428575
                2 .0008149959
                1   .01754386
                2   .01754386
                1    .0909091
                1  .071428575
                2 .0008149959
                1 .0008149959
                1  .011494253
                2  .003521127
                2   .00862069
                1 .0008149959
                2  .004694836
                2 .0008149959
                2    .0909091
                2 .0008149959
                1 .0008149959
                1 .0008149959
                1   .03448276
                2 .0008149959
                1 .0008149959
                1  .033333335
                2    .0909091
                2  .009259259
                2  .004694836
                2  .009259259
                1 .0008149959
                2  .003521127
                2  .004694836
                1   .02857143
                1   .03448276
                2 .0008149959
                1  .004694836
                1   .03448276
                2   .03448276
                2 .0008149959
                1  .003521127
                1   .00862069
                1   .00862069
                1    .0909091
                1 .0008149959
                1  .004694836
                2   .06666667
                2 .0008149959
                1   .07692308
                2 .0008149959
                1   .04761905
                1 .0008149959
                2 .0008149959
                2 .0008149959
                1   .02857143
                2 .0008149959
                2  .003521127
                1          .1
                1  .011494253
                2 .0008149959
                1 .0008149959
                2 .0008149959
                2 .0008149959
                1  .010416667
                2 .0008149959
                2   .04166667
                1          .1
                1 .0008149959
                1 .0008149959
                1   .06666667
                1  .004694836
                2   .04166667
                1   .04545455
                1   .00862069
                2 .0008149959
                1   .04545455
                2  .010416667
                1   .06666667
                1   .01754386
                2 .0008149959
                1 .0008149959
                2 .0008149959
                1  .004694836
                1 .0008149959
                1  .033333335
                2 .0008149959
                2 .0008149959
                1 .0008149959
                1  .004694836
                2  .003521127
                2 .0008149959
                1 .0008149959
                1 .0008149959
              700  .003521127
                1  .009259259
                2  .003521127
                2 .0008149959
                1  .011494253
                2 .0008149959
                2   .00862069
                1 .0008149959
                1  .071428575
                1  .010416667
                2 .0008149959
                2  .004694836
                2 .0008149959
                2 .0008149959
                2  .003521127
                2  .003521127
                1  .071428575
                1 .0008149959
                2  .011494253
                2 .0008149959
                2   .04545455
                2   .00862069
                2 .0008149959
                1 .0008149959
                2 .0008149959
                1   .00862069
                1   .00862069
                1   .04166667
                1 .0008149959
                . .0008149959
                2 .0008149959
                2 .0008149959
                2  .009259259
                1 .0008149959
                2 .0008149959
                2 .0008149959
                2 .0008149959
                .  .033333335
                2 .0008149959
                2  .003521127
                1 .0008149959
                2  .010416667
                2  .003521127
                2  .004694836
                1  .003521127
                1 .0008149959
                2 .0008149959
                2   .01754386
                .  .011494253
                1   .06666667
                1   .03448276
                1   .00862069
                2 .0008149959
                1    .0909091
                1    .0909091
                2 .0008149959
                1   .00862069
                1  .004694836
                1  .011494253
                2 .0008149959
                2 .0008149959
                2 .0008149959
                2  .033333335
                1 .0008149959
                1  .003521127
                2 .0008149959
                1   .04545455
                1  .004694836
                2  .009259259
                2 .0008149959
                2 .0008149959
                2  .003521127
                2 .0008149959
                2 .0008149959
                2 .0008149959
                1  .071428575
                1  .011494253
                1  .004694836
                .  .033333335
                2  .009259259
                2 .0008149959
                2   .04545455
                2 .0008149959
                1   .02857143
              700  .003521127
                2 .0008149959
                1 .0008149959
                1  .011494253
                1   .00862069
                2   .03448276
                1 .0008149959
                2  .003521127
                2 .0008149959
                2  .071428575
                2   .01754386
                2 .0008149959
                2  .004694836
                1 .0008149959
                1  .003521127
                1  .003521127
                2 .0008149959
                1  .009259259
                2 .0008149959
                2 .0008149959
                2 .0008149959
                1    .0909091
                2  .004694836
                1  .010416667
                1  .003521127
                2  .010416667
                1   .04545455
                1  .010416667
                .  .033333335
                1    .0909091
                1  .004694836
                2 .0008149959
                2 .0008149959
                2 .0008149959
                1  .003521127
                2  .004694836
                1  .071428575
                1 .0008149959
                1 .0008149959
                1 .0008149959
                2  .003521127
                2  .003521127
                2 .0008149959
                1 .0008149959
                2 .0008149959
                1    .0909091
                1   .01754386
                1   .00862069
                2 .0008149959
                2  .003521127
                2 .0008149959
                2 .0008149959
                2  .003521127
                2 .0008149959
                1 .0008149959
                1         .04
                .  .009259259
                2  .003521127
                1   .03448276
                1 .0008149959
                2  .011494253
                2  .003521127
                2 .0008149959
                1 .0008149959
                2  .009259259
                2    .0909091
                2 .0008149959
                1   .06666667
                2 .0008149959
                2 .0008149959
                2 .0008149959
                2 .0008149959
                2 .0008149959
                2 .0008149959
                1  .010416667
                1    .0909091
                1 .0008149959
                2 .0008149959
                2 .0008149959
                1 .0008149959
                2 .0008149959
                1  .071428575
                1  .011494253
                1   .04761905
                2 .0008149959
                2  .003521127
                1 .0008149959
                .  .009259259
                1 .0008149959
                2  .004694836
                2 .0008149959
                1  .011494253
                2   .00862069
                1  .011494253
                1 .0008149959
                2 .0008149959
                1   .00862069
                1   .07692308
                1  .003521127
                2 .0008149959
                2 .0008149959
                2  .004694836
                1  .004694836
                2 .0008149959
                2 .0008149959
                1 .0008149959
                2          .1
                1 .0008149959
                1 .0008149959
                1 .0008149959
                2  .009259259
                1  .009259259
                .  .009259259
                2   .00862069
                1   .04545455
                1   .05555556
                2 .0008149959
                1  .011494253
                2   .00862069
                1    .0909091
                1   .00862069
                2 .0008149959
                1 .0008149959
                1  .003521127
                2  .003521127
                2         .04
                2  .003521127
                2 .0008149959
                2   .04166667
                2  .009259259
                2   .03448276
                2  .003521127
                2 .0008149959
                1    .0909091
                1  .004694836
                2 .0008149959
                2 .0008149959
                1  .009259259
                1  .003521127
                1  .010416667
                2  .009259259
                2 .0008149959
                2  .009259259
                2 .0008149959
                1  .009259259
                1   .02857143
                2 .0008149959
                2  .009259259
                1  .010416667
                2 .0008149959
                2 .0008149959
                2 .0008149959
                1 .0008149959
                2  .009259259
                2  .003521127
                1 .0008149959
                2 .0008149959
                1   .04545455
                2  .009259259
                1  .003521127
                2 .0008149959
                2  .003521127
                2 .0008149959
                2 .0008149959
                1 .0008149959
                1 .0008149959
                1   .01754386
                1   .01754386
                2  .009259259
                2 .0008149959
                2 .0008149959
                1  .010416667
                1          .1
                2  .003521127
                2 .0008149959
                1   .04166667
                1   .04545455
                2 .0008149959
                2  .009259259
                2 .0008149959
                2 .0008149959
                1  .004694836
                2  .004694836
                1  .004694836
                1   .04545455
                2 .0008149959
                1 .0008149959
                1 .0008149959
                1   .06666667
                1 .0008149959
                1 .0008149959
                2  .010416667
                1  .009259259
                1   .04545455
                2 .0008149959
                1   .05555556
                2 .0008149959
                2 .0008149959
                2  .003521127
                2  .004694836
                2 .0008149959
                2  .011494253
                2    .0909091
                2 .0008149959
                2  .010416667
                2 .0008149959
                2  .003521127
                1  .003521127
                2 .0008149959
                1  .004694836
                2 .0008149959
                1  .004694836
                1          .1
                1   .00862069
                1  .010416667
                2 .0008149959
                2  .003521127
                2 .0008149959
                2  .011494253
                2  .004694836
                2 .0008149959
                2   .01754386
                2 .0008149959
                1   .04545455
                2   .06666667
                2 .0008149959
                1 .0008149959
                1  .004694836
                2 .0008149959
                1 .0008149959
                1  .004694836
                1 .0008149959
                2 .0008149959
                1  .004694836
                1  .009259259
                1  .009259259
                1 .0008149959
                2   .06666667
                2 .0008149959
                2  .004694836
                2 .0008149959
                2 .0008149959
                1   .01754386
                2  .003521127
                2  .003521127
                1 .0008149959
                1 .0008149959
                2   .04545455
                1 .0008149959
                1    .0909091
                2 .0008149959
                .  .033333335
                1  .003521127
                2 .0008149959
                1  .004694836
                2 .0008149959
                2  .003521127
                1 .0008149959
                2         .04
                2   .04761905
                1 .0008149959
                2 .0008149959
                2  .003521127
                1 .0008149959
                2 .0008149959
                1    .0909091
                2  .003521127
                1  .010416667
                2 .0008149959
                .  .033333335
                .  .033333335
                1  .004694836
                2  .009259259
                1 .0008149959
                2 .0008149959
                1  .010416667
                1 .0008149959
                1 .0008149959
                2  .004694836
                1  .010416667
                1 .0008149959
                2 .0008149959
                2   .00862069
                1          .1
                2  .004694836
                2  .003521127
                2 .0008149959
                2  .004694836
                1 .0008149959
                2  .011494253
                1          .1
                2          .1
                2  .003521127
                2 .0008149959
                2 .0008149959
                2 .0008149959
                1   .04545455
                2         .04
                1 .0008149959
                2 .0008149959
                2  .003521127
                2 .0008149959
                2  .003521127
                2 .0008149959
                2 .0008149959
                2 .0008149959
                2 .0008149959
                1         .04
                2 .0008149959
                1  .010416667
                2   .00862069
                1   .03448276
                1   .02857143
                1  .003521127
                2  .009259259
                1 .0008149959
                1  .004694836
                2   .06666667
                2 .0008149959
                2  .010416667
                1  .004694836
                1  .010416667
                1 .0008149959
                1 .0008149959
                2   .01754386
                2  .004694836
                2 .0008149959
                1 .0008149959
                1  .010416667
                2 .0008149959
                2   .00862069
                2  .003521127
                1 .0008149959
                2   .03448276
                1 .0008149959
                1 .0008149959
                2 .0008149959
                1  .003521127
                1 .0008149959
                2  .011494253
                2 .0008149959
                1 .0008149959
                2  .011494253
                1   .00862069
                2 .0008149959
                2 .0008149959
                2   .01754386
                2  .009259259
                1  .004694836
                2 .0008149959
                1  .003521127
                1 .0008149959
                1 .0008149959
                2 .0008149959
                1   .00862069
                1 .0008149959
                1 .0008149959
                2  .003521127
                2  .033333335
                1  .004694836
                1    .0909091
                1 .0008149959
                2 .0008149959
                1 .0008149959
                1  .004694836
              end
              label values dem2 dem2
              label def dem2 1 "Male", modify
              label def dem2 2 "Female", modify
              label def dem2 700 "Other", modify
              I am using the code below based on the previous posts

              Code:
                  gl barsettings1 "bar(1, fcolor(navy) fintensity(inten40) lcolor(navy) lwidth(medium))"
                  expand 2, gen(indicator)
                  lab def indicator 0 "Unweighted" 1 "Weighted"
                  lab val indicator indicator
                  tab indicator
                  replace weight = 1 if indicator == 0
                  
                  count if !mi(dem2)
                  catplot dem2 indicator [iweight = weight], blabel(bar, format(%3.0f)) l1title("") title("") ytitle("Percent") percent $barsettings1
              I would appreciate any further guidance!

              Comment


              • #8
                I would have thought that you need percent(indicator) to enforce separate calculations.

                Comment


                • #9
                  Nick Cox That was exactly the way out. I am really grateful!!!

                  Comment

                  Working...
                  X